I'm looking to create a new app from scratch and will probably use Spring MVC and possibly Spring Web Flow. The projects created by Spring Roo use Spring MVC and optionally Web Flow. What are some good alternatives for view technology, or is JSP with Spring and JSTL taglibs and jQuery the way to go?
-
15For anyone that is interested, I ended up going with JSP in the end and it has worked out very well. With the re-usability provided with jsp tag files and the nice taglibs available in spring and jstl it's not the horrible JSP I remember from 2004 with tons of scriptlets and all that. – digitaljoel Oct 03 '11 at 15:27
-
Kindly suggest the alternative . – praveenpds Sep 16 '16 at 09:16
-
1Here is the related section in the official Spring MVC documentation: [**View Technologies**](https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-view). – informatik01 Jul 06 '19 at 23:43
16 Answers
I recently discovered Thymeleaf.
It looks to be a complete replacement for JSPs and has integration with Spring MVC. The template approach looks more like HTML and may be more palatable to your UI designers. They have a small write-up that compares the two solutions side-by-side.

- 1,968
- 2
- 19
- 30
-
3Thymeleaf by itself is great, but together with layout dialect [layout dialect](https://github.com/ultraq/thymeleaf-layout-dialect) I love it! – Filip Spiridonov Feb 23 '13 at 09:37
-
Why should I use thymeleaf while facelets? Also, facelet's template approach looks like html and more..Why should we use it? What makes it a good thing according to facelets? for me "Nothing". maybe thymeleaf greater than jsp.So java ee most recent developed 'facelets' for the template language.And so JSP is old technology.Why would you compare with him?its an old technology?Sorry my bad English. – erginduran Jul 08 '15 at 19:51
In the standard Java EE API, the only alternative to JSP is Facelets. As far now (2010) JSF is the only MVC framework which natively supports Facelets.
Spring MVC supports out of the box only JSP, but it has a configurable view resolver which allows you to use Facelets anyway. Other candiates are 3rd party templating frameworks such as Velocity, Freemarker, and Thymeleaf which can be configured as a view technology for Spring MVC. Spring documentation has integration examples with Velocity and Freemarker.

- 22,894
- 45
- 188
- 319

- 1,082,665
- 372
- 3,610
- 3,555
-
"As far now (2010) JSF is the only MVC framework which natively supports Facelets." Did you mean "As far now (2010) Facelets is the only view technology which natively supports the JSF MVC framework."? Isn't Facelets (which is a view technology) supposed to _suppport_ a MVC framework like JSF? (Sorry if what I say does not make sense, I am very new to JSF stuff). – Utku Jun 15 '17 at 08:19
-
1Facelets is included in JSF itself since JSF 2.0. So you don't need to install it separately. Facelets itself can be used with any other MVC framework such as Spring MVC, but you'd have to install and configure it manually. – BalusC Jun 15 '17 at 09:45
I recently started going with plain HTML and jQuery for presentation with Spring MVC only creating a JSON view.
So far it's going quite well and even though I have to do the javascript work, it makes for much easier interaction with my designer and quicker turnaround times when he has changes because I don't have to convert his HTML into my JSP. The jury is still out on overall site maintainability.

- 26,265
- 15
- 89
- 115
-
-
your restful api can do whatever you want. For pagination just add a start and end or offset and page size or whatever you need to get the appropriate results. – digitaljoel Nov 07 '12 at 16:13
-
Hi, I know this is late, but just a hint, Thymeleaf attempts to address the exact problem you mention in your answer (developer-designer interaction). It is probably worth a look, then. – acdcjunior Dec 03 '13 at 22:54
-
thanks @acdcjunior. I went to a presentation on Thymeleaf at SpringOne and it looked pretty interesting and natural until the presenter said in his tests Thymeleaf was 8x - 10x slower than JSP. – digitaljoel Dec 04 '13 at 17:47
-
Yeah, indeed it is slower. Check this thread: http://forum.thymeleaf.org/Performance-issue-td3722763.html . For me, that was the reason I didn't dive blindly into it (coz normally I develop for internet portals), but for "intranet" apps, those where JSF would be acceptable, I feel thymeleaf would be too. Hopefully, though, their performance improve in the future. Cheers! – acdcjunior Dec 04 '13 at 18:06
-
If you are going front-end based view binding, why not try Angular JS ? – Mushtaq Jameel Jul 28 '14 at 11:43
-
Angular is already on my list of things to try. I would lump any of those into the HTML/javascript solution bucket. Sadly iteration time is long enough that changing technologies is a bit of an undertaking. Thanks for the suggestion. – digitaljoel Jul 28 '14 at 21:41
-
Hi I'm also interested in plain HTML5 and jQuery for front end with restful for communication. But I don't know how to choose web container for such design. For example, if you choose `jsp` you could use `tomcat`. So in your case, what container or web app server do you choose? – macemers Sep 11 '15 at 09:24
-
Springs 3 documentation also suggests FreeMarker. Freemarker is (as far as I can tell) fast and has some integration of Spring features like binding.

- 16,038
- 10
- 74
- 104

- 4,781
- 2
- 37
- 50
You can have as many view technologies as you want on Spring MVC. I have FreeMarker and JSP view resolvers. When I run into a view that it's too complicated in FreeMarker (or just more convenient in JSP) I create a JSP view. For instance, Spring with JSTL makes a great job handling forms. For that I use JSP views, but for pretty much everything else I have FreeMarker views.
Have a look to the Spring MVC documentation to see how to configure several view resolvers, basically:
<bean name="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value=""/>
<property name="suffix" value=".ftl"/>
<property name="order" value="1"/> <!--NOTICE THE ORDER-->
</bean>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
<property name="order" value="2"/> <!--NOTICE THE ORDER-->
</bean>

- 16,038
- 10
- 74
- 104

- 3,659
- 2
- 32
- 27
Spring MVC provides integration with many different view technologies. I would recommend using FreeMarker or Velocity.

- 35,493
- 19
- 190
- 259

- 126
- 3
While this is an old question I thought I would offer an up-and-coming alternative which is Scalate.
Scalate is powerhouse in templating options. The only probablem is that Scalate requires lots of dependencies (while it requires Scala it does not require you write in Scala).
My current favorite though is Handlebars.java which does have Spring integration.

- 47,843
- 23
- 153
- 203
-
Interesting that it doesn't list any Spring compatibility. Have you successfully integrated it with Spring MVC? – digitaljoel Jan 23 '12 at 19:40
-
http://stackoverflow.com/questions/5913373/scala-spring-and-scalate and https://github.com/scalate/scalate/tree/master/scalate-spring-mvc . I did something similar to the former. Spring is rather easy to integrate other stuff wiht. – Adam Gent Jan 23 '12 at 21:42
-
@digitaljoel See also [Using Scalate with Spring MVC](http://scalate.fusesource.org/documentation/spring-mvc.html) – arashi01 Dec 06 '12 at 11:00
(My previous answer was getting badly dated here.) Freemarker is at least as good as Velocity. But Thymeleaf is looking even more compelling, together with layout-dialect it may make template frameworks like sitemesh and tiles unnecessary. For JSF, Thoughtworks' criticism seems valid:
We continue to see teams run into trouble using JSF - JavaServer Faces - and are recommending you avoid this technology. Teams seem to choose JSF because it is a Java EE standard without really evaluating whether the programming model suits them. We think JSF is flawed because its programming model encourages use of its own abstractions rather than fully embracing the underlying web model. JSF, like ASP.NET webforms, attempts to create stateful component trees on top HTML markup and the stateless HTTP protocol. The improvements in JSF 2.0 and 2.2, such as the introduction of stateless views and the promotion of GET, are steps in the right direction, maybe even an acknowledgement that the original model was flawed, but we feel this is a too little too late. Rather than dealing with the complexity of JSF we recommend teams use simple frameworks and work closely with web technologies including HTTP, HTML and CSS.

- 94,330
- 19
- 181
- 276
-
Why is it the best alternative? The error checking in velocity is pretty bad. So why is it better? – Adam Gent Oct 09 '10 at 15:49
-
@Adam: it is a lot simpler, and doesn't allow scriptlets, I count those as improvements over JSP. I remember writing tests for my velocity templates was pretty simple too. – Nathan Hughes Oct 11 '10 at 00:08
I am using velocity and Spring MVC. Also, i am hosting my application on Googles App engine and I have no issues.

- 2,183
- 3
- 17
- 26
You could also use Angular (Client side framework) for your View layer in Spring MVC.

- 2,027
- 1
- 19
- 19
-
-
If I understand you correctly you would like to ask if Angular does serverside redering. Starting from Angular 2.x it provides this functionality. You can have a look at this reference: [Server-side Rendering](https://angular.io/guide/universal) – ddsultan Sep 10 '18 at 12:08
-
Sorry I should have been more specific. I meant is there a way to server side render an Angular app within Java without a nodejs server? – protoEvangelion Sep 10 '18 at 16:12
-
1There is one community project you might want to check for Java: [Angular UniversalJ](https://github.com/swaechter/angularj-universal). I think it utilizes Node in the background. – ddsultan Sep 10 '18 at 16:48
I think Tiles could help you.
You can define templates and use JSTL inside.

- 35,493
- 19
- 190
- 259

- 490
- 5
- 8
My suggestions is not to look at view framework as described in most of the above which was not written on top of spring MVC since you will end up in issues like postbacks which means you won't be able to submit the data from this view technology and get back the response from sever. example like validation , edit data submission which refreshes back with data from server WILL NOT WORK .
This is because java beans in some above of view technology don't use Spring container lifecycle. You will only be able to use them for pure view example stateless request. example with JSF you won't be able to use postbacks since jsf postbacks only work if you use jsf life cycle and if you use spring framework JSF view resolver with spring mvc you won't be able to do postback so you need to replace jsf servlet controller instead of spring mvc controller .
Again since your full project requirement is not clear and if you want no postback requirement you can use some of above choices .
one example view technology which is written on top og spring mvc is zk framework based zk mvc in which you can extend your spring mvc controllers from ZK GenericForwardComposer to handle events. You can always use Spring to handle the lifecycle of these controllers using Spring framework.
you can google to find similiar other products .
This review is based on high level design of framework life cycle.
All the best !!!

- 113
- 1
- 8
What about phpj?
It can be used as view templates or you can make your web server system from scratch
I made phpj because i dont like to having to update my application and load it with tomcat all the time, so with this i can use static locations for my web application using apache-like configurations

- 11
- 1