tags:

views:

1020

answers:

6

Are there any alternatives to JSTL? One company I worked for 3 years ago used JSTL and custom tag libraries to separate presentation from logic. Front-end developers used EL to do complex presentation logic, generate layouts in JSP pages and it worked out great. Perhaps new technologies have come out. Anything better these days?

+6  A: 

I've used velocity with great success and it works great as a simple way to separate business logic from presentation logic. And it's simple enough that your average web developer can understand it. Freemarker is another templating alternative that a lot of people like, as well.

Marc Novakowski
+1  A: 

JSTL is a tag library containing logic functions that can be used inside a JSP page. Other such libraries also exist, but most probably you want to look at revised approaches to the whole jsp/jstl solution.

Most notably I would recommend looking at:

Apache Wicket

JSF with facelets

Google Web Toolkit (GWT)

krosenvold
A: 

I won't say they're a replacement or alternative, but I think Java-Server-Faces go a step further in separation presentation from logic...

Argelbargel
+1  A: 

Assuming you're looking for an easier way to develop an application using MVC I would highly recommend looking at the Spring Framework. Spring has its own tag lib that provides most of what you should need in the JSPs. I have had great success using Spring webflow along with the Spring forms tag lib. I like to divide the application up into a persistence layer (using Spring's ORM support for Hibernate), a service layer (business logic), and a view layer. The view layer includes the web flows, JSPs, and POJOs for validations and actions. I have also used DWR in the view layer for AJAX calls.

rich
+9  A: 

JSTL and EL are two distinct concepts.

JSTL is just one tag library. Most frameworks provide their own taglib that approximately duplicates the functionality of JSTL. I say approximately, because these often misuse or overlook key principles of JSP and the Servlet API.

The strength of JSTL is that it was designed by the authors of JSP, with a solid understanding of JSP and servlets. Third-party taglibs are often created by some guy who didn't want to RTFM and decided to "start from scratch" and come up with "something simpler". However, JSTL wasn't intended to do everything. It can be used very successfully in conjunction with other taglibs, including your own custom tags.

Expression language is fundamental to JSP. It is interpreted by the container, and can be used in many contexts. It is also largely side-effect free, and has a simple, easily comprehensible syntax that doesn't allow a lot of logic to get stuffed into the presentation layer. Being part of the JEE spec, it also enjoys wide tool support. For example, many IDEs can refactor dependent EL expression when you rename a property.

Struts2 introduced OGNL to a wider audience. OGNL is a throwback to the evil days of scriptlets. It is more powerful, and so developers happily abuse it to invoke arbitrary methods in the presentation layer and other atrocities. I was familiar with OGNL from years of previous experience with WebWork, and my greatest hope for the adoption of WebWork by Struts was that they would jettison this dreck. Luckily, because of its clumsy integration, it can only be used in the context of OGNL-aware tags, unlike EL, which is supported by the container itself.

If you want to get away from JSP, but aren't into a component-based approach like JSF, you might check out Terrence Parr's StringTemplate project. The focus there is to be side-effect free, which has important implications for safety and scalability.

erickson
+3  A: 

JSTL encourages you to put logic in your UI. Try Apache Wicket instead where logic is done in java.

Agreed, separation of concerns doesn't get any cleaner than Wicket.
jonathan.cone