开发者

Fastest Java web templating language

I'm about to start in on a new Spring MVC project, and I'm examining the various options for the view. I've never been a fan of JSP, and I've run into JSP-related performance problems in the past, so I was looking through the other options. I'm hoping that somewhere somebody's taken a census of the various options (maybe it'll have to be me) a开发者_开发技巧nd pronounced which ones are quick, or at least which options there are. Here are the choices I've thought of, ordered from obvious to bizarre:

  • JSP, JSTL
  • Velocity
  • FreeMarker
  • GSP (Groovy JSP)
  • ERB powered by IronRuby or some such craziness
  • Tea

Any suggestions, personal preferences, or other good options for the list?


StringTemplate - fast, simple and helps enforce MVC separation of concerns. Last I checked, Spring Web MVC doesn't provide a View class for it, but I was able to easily create a custom one.


While I would probably go with FreeMarker or Velocity myself, I am surprised at what you call

JSP-related performance problems

Of all these possible solutions, JSP is obviously the best-performing. After all, JSP pages are compiled to Servlet classes and executed from byte code whereas all the other technologies you mentioned are interpreted.

If you have performance problems, either optimize your JSP code or use a JSP compiler like JSPC to pre-compile your JSP pages (perhaps with maven, using the JSPC-maven-plugin).


I prefer Velocity these days. The performance is fine. I like the natural way it decouples the template and the data.


I used to use Velocity. The project stagnated a bit and had some known issues, so switched over to Freemarker. I believe (don't quote me) Freemarker came about because Velocity lost momentum. No pun intended.

Since then Velocity has become active again, at least for a while. I prefer Freemarker right now, but either of these two work well. I'd go with whichever one plugs in easier to Spring MVC.


I agree with Sean Patrick Floyd that JSP should be realy fast. In most cases even faster then the other Template engines, even if they are cached.

If you realy run in an JSP related performance issue than I belive you should rethink the way how you use JSP.

And at least, if you have a hot spot which causes the performance issue, than you can build this (hopeflully) small pice by hand (StringBuilder).

So to wrapp this up: I belive JSP is the fasted one (except doing it by hand), but on the other hand, you must have a very special use case to run in a perfomace issue with any of the major template engienes you mentioned.


You should try MVEL. It is faster than anything i know (incl. StringTemplate), really powerful and feels like scripting in plain java.

<p>
   @foreach{index : alphabetical}
     <a href="@{index.uri}">@{index.description}</a>
   @end{}
</p>

or

<a href="@{ua.pageURI}">
   @{org.apache.commons.lang.StringEscapeUtils.escapeHtml(ua.name)}
</a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜