Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Type-safe alternatives to JSP templating

Tags:

java

jsp

Is there something safer than JSP? I haven't found any meaningful answers through Google. We currently use the Spring MVC framework and JSP to render HTML. I have came to hate the dynamic nature of the JSP rendering, in that you reference a model like ${model.someAttribute} but have no way of telling whether this attribute is available at the given module or specifies the type of the model that the template expects. It becomes very difficult to refactor the models' getters since Eclipse doesn't know which templates use the model and also cannot relate the getters to the property accessors in templates.

Is there a templating technology out there, that is both less ugly than spitting out HTML code via imperative code and more type/compile safe than JSPs?

like image 307
d56 Avatar asked Feb 21 '13 22:02

d56


People also ask

What is the alternative of JSP?

FreeMarker: An open alternative to JSP.

Is JSP a template engine?

Spring MVC, Struts or Apache Wicket are examples of web frameworks, whereas JSP, Velocity or FreeMarker are examples of template engines.


1 Answers

You can use type hints, e.g. the type attribute in jsp:useBean and in the attribute declarations of JSP tag files (and probably in other places like JSTL tags). IntelliJ will then do all the good static type-based stuff for you (accurate code completion suggestions, refactoring, find usages, show quick javadoc, etc.).

I just recently wrote about this in the context of JSP tag files.

like image 194
oldo Avatar answered Sep 30 '22 20:09

oldo