Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benefits of using JSTL vs Velocity for view layer in MVC app?

I'm currently building a Spring MVC application. I was looking to use JSP pages with tag libraries for handling the view layer and formatting of the HTML, but I've come across another group in my company that uses Velocity templates for the same purpose.

From what I can see, it seems to me as if there are a lot of similarities between the two approaches:

  1. Both have easy-to-understand syntax. Makes it easy for non-developers to understand and use, allowing the designers to focus on the HTML/CSS and only having to use directives/tag libraries in the few cases where they need conditionals/dynamic content without having to have a full understanding of Java.
  2. Simple to see which part of the content is HTML vs which are directives/logic.
  3. Both are heavily used and well supported.
  4. Simple to integrate with Spring MVC.

But in comparing the two technologies, I can't see any specific reasons to use one versus the other. I'm having trouble thinking of any cons specific to either Velocity or JSTL.

So my question is, what are the pros and cons of each in your opinion? If you have built a (Spring) MVC app using one or the other, what made you decide on the view layer technology you are using and what (if anything) made you decide against the other?

Update: I've found a similar discussion of this same topic archived on the Spring Framework forum's here, which might be of some interest to anyone making the same decision between JSTL and Velocity as I am.

like image 375
matt b Avatar asked Dec 19 '08 15:12

matt b


2 Answers

I would prefer to use Velocity just because using JSP+JSTL can allow lazy/sloppy developers to get into trouble by adding scriptlets. There should be no reason to have java code in your view tier. It doesn't take much to understand Velocity and as a matter of fact I just picked it up in about two weeks. While I don't like the formatting of the output, for the most part it works pretty well. We're actually not using it in the app's view tier but rather for generating HTML for use by other browsers. We save the output from Velocity as files which is then deployed to a different server for consumption by other web clients.

like image 143
BenCourliss Avatar answered Sep 19 '22 11:09

BenCourliss


I actually slightly prefer Freemarker to Velocity, just in case you're open to exploring other options. Comparison here:

http://freemarker.org/fmVsVel.html

I agree with Ben's statements about enforcing a simple view by avoiding JSP and the possibility of scriptlets. I also like the ability to render a Freemarker or Velocity template in any kind of execution environment (JUnit, main() method) without requiring a Servlet/JSP container as JSP would.

like image 24
cliff.meyers Avatar answered Sep 21 '22 11:09

cliff.meyers