Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

The Geronimo renegade: Using integrated packages: GlassFish JSTL 1.2 and Apache Geronimo 2.0

JSTL and Geronimo 2.0 give you more choices than ever when building Java Web applications

Michael Galpin (mike.sr@gmail.com), Developer, Adomo, Inc.
Michael Galpin's photo
Michael Galpin has been developing Java software professionally since 1998. He holds a degree in mathematics from the California Institute of Technology and currently works at Adomo, Inc.

Summary:  The Apache Geronimo team has successfully implemented the exciting new Java™ Platform, Enterprise Edition (Java EE) 5.0 specification. One of the many notable features of Java EE 5 is the new Java Standard Tag Library (JSTL) 1.2 specification. The key to JSTL 1.2 is the unified expression language, which lets you use the best features of JSTL alongside the JavaServer Faces (JSF). In this installment, the renegade covers the importance of JSTL 1.2 by examining the history of Java Web technologies and how the Geronimo team has leveraged the GlassFish JSTL 1.2 implementation to add JSTL 1.2 support to Geronimo.

View more content in this series

Date:  28 Aug 2007
Level:  Intermediate
Also available in:   Russian  Japanese

Activity:  9091 views
Comments:  

Evolution of Java Web technologies

The Enterprise Java language has always included Web technologies. These started out with servlets and have evolved from there.

Servlets

Servlets were originally used to respond to HTTP requests. Writing a servlet was generally a pretty ugly affair. Take a look at an example in Listing 1.


Listing 1. Servlet generating HTML
                
     protected void doGet(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException {
          ServletOutputStream out = response.getOutputStream();
          out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 
Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
          out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
          out.println("<head>");
          out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; 
charset=ISO-8859-1\" />");
          out.println("<title>All Users</title>");
          out.println("</head>");
          out.println("<body>");
          out.println("     <table>");
          out.println("          <tr>");
          out.println("               <td>UserID</td>");
          out.println("               <td>UserName</td>");
          out.println("               <td>Name</td>");
          out.println("          </tr>");

          UserDao dao = new UserDao();
          List users = dao.getAllUsers();
          for (int i=0;i<users.size();i++){
               User user = (User) users.get(i);
               out.println("          <tr>");
               out.println("               <td>"+user.getId()+"</td>");
               out.println("               <td>"+user.getUserName()+"</td>");
               out.println("               <td>"+user.getFirstName()+' 
'+user.getLastName()+"</td>");
               out.println("          </tr>");
          }
          out.println("     </table>");
          out.println("</body>");
          out.println("</html>");
     }

Servlets involved lots of HTML (for example) being embedded in Java code. The only thing more difficult than developing servlets was maintaining them. Imagine that you wanted to change the table to have a border in the code in Listing 1. Doing so involved changing Java code and recompiling the servlet. Luckily, servlets were soon augmented with JavaServer Pages (JSP) technology.

JavaServer Pages

JSP technology enhanced Java servlets. JSP components offered a lot of improvements over servlets, including allowing the native markup to be mixed with Java code. Listing 2 shows the same servlet shown in Listing 1 as a JSP component.


Listing 2. JSP 1.0 version
                
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="org.developerworks.*" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>All Users</title>
</head>
<body>
     <table>
          <tr>
               <td>UserID</td>
               <td>UserName</td>
               <td>Name</td>
          </tr>
          <%
               UserDao dao = new UserDao();
               List users = dao.getAllUsers();
               for (int i=0;i<users.size();i++){
                    User user = (User) users.get(i);
          %>
          <tr>
               <td><%= user.getId() %></td>
               <td><%= user.getUserName() %></td>
               <td><%= user.getFirstName() %> <%= user.getLastName() 
                 %></td>
          </tr>
          <%
               }
          %>
          </c:forEach>
     </table>
</body>
</html>

Obviously, what you see in Listing 2 is a big improvement over the servlet. JSP components were still compiled into a servlet, but this was done by the servlet container (or it could be done as part of a build). So, a JSP component could offer the same performance as a servlet. The PHP syntax is similar to Active Server Page (ASP) and PHP pages, but the compiling into a servlet gave JSP components a significant performance advantage over these other technologies.


JSP Model 2

There are still some significant issues to the JSP code shown in Listing 2. It uses a scriptlet, which is a small piece of Java code. Using scriptlets presented problems from both a design and a practical standpoint. The JSP components freely mixed business logic (retrieving the list of users) with presentation. The JSP Model 2 architecture evolved to solve this. A servlet could be used in conjunction with the JSP component. Take a look at Listing 3.


Listing 3. Model 2-style servlet
                
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException {
        UserDao dao = new UserDao();
        List users = dao.getAllUsers();
        request.setAttribute("users", users);
        request.getRequestDispatcher("/user.jsp").forward(request, response);
    }

The servlet could first handle the request and perform business logic. It could then store the results in the HttpServletRequest object and forward to a JSP component. This allowed the JSP component to be simplified, as seen in Listing 4.


Listing 4. Model 2-style JSP component
                
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="org.developerworks.*" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>All Users</title>
</head>
<body>
    <table>
        <tr>
            <td>UserID</td>
            <td>UserName</td>
            <td>Name</td>
        </tr>
        <%
            List users = (List) request.getAttribute("users");
            for (int i=0;i<users.size();i++){
                User user = (User) users.get(i);
        %>
        <tr>
            <td><%= user.getId() %></td>
            <td><%= user.getUserName() %></td>
            <td><%= user.getFirstName() %> <%= user.getLastName() 
   %></td>
        </tr>
        <%
            }
        %>
        </c:forEach>
    </table>
</body>
</html>

That solves some of the architectural issue. However, there's still a practical problem. The mixing of Java code and HTML makes the JSP components difficult to work with for both Java developers who don't know HTML that well and for Web designers who don't know the Java language well.

The JavaServer Pages Standard Tag Library (JSTL)

Cleaning up JSP components to remove any Java scriptlets became a goal for JSP technology. The end result of this quest was the JSTL. The JSTL introduced HTML-style tags for accessing Java objects and performing many of the constructs of the Java programming language, such as iterating over collections, conditional logic, and formatting text. JSTL allows the JSP component to evolve, as shown in Listing 5.


Listing 5. JSP with JSTL
                
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>All Users</title>
</head>
<body>
     <table>
          <tr>
               <td>UserID</td>
               <td>UserName</td>
               <td>Name</td>
          </tr>
          <c:forEach items="${users}" var="user">
          <tr>
               <td><c:out value="${user.id}"/></td>
               <td><c:out value="${user.userName}"/></td>
               <td><c:out value="${user.firstName}"/> <c:out
 value="${user.lastName}"/></td>
          </tr>
          </c:forEach>
     </table>
</body>
</html>

The <c:forEach> tag allows iteration over the list of users. The <c:out> tag allows the Java object to be accessed and its data output.

The expressions used in the tags, such as ${users} and ${user.id}, were interpreted by the JSTL Expression Language (EL). For example, the EL interprets the string ${users} and looks for an attribute called users in the various objects accessible, such as the pageContext, request, session, and servlet (application) context. JSP components evolved further to allow the EL to be accessed outside of JSTL tags. This leads to the JSP components in Listing 6.


Listing 6. JSP using JSTL and EL
                
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>All Users</title>
</head>
<body>
     <table>
          <tr>
               <td>UserID</td>
               <td>UserName</td>
               <td>Name</td>
          </tr>
          <c:forEach items="${users}" var="user">
          <tr>
               <td>${user.id}</td>
               <td>${user.userName}</td>
               <td>${user.firstName} ${user.lastName}</td>
          </tr>
          </c:forEach>
     </table>
</body>
</html>

This is the modern form of JSTL and the EL first seen in the JSP 2.0 specification. When coupled with a Model 2 architecture (often implemented by various UI frameworks, such as Apache Struts and others), this combination of the JSTL and EL lets you build JSP components that are essentially Java free. This allows non-Java programmers to work with the JSP components and lets Java developers concentrate on implementing the business logic of their applications.

JavaServer Faces technology

However, JSP technology isn't the only Web technology that's part of the Enterprise Java architecture. Shortly after the JSP 2.0 specification debuted, JSF technology also debuted. JSF was designed to be a component architecture. Objects on a Web page are viewed as components with a life cycle and with Java objects bound to them. Thus, in this article's JSP example, you can directly bind the Java object to the view component using JSF. The resulting JSP component is shown in Listing 7.


Listing 7. JSP using JSF
                
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http:.//java.sun.com/jsf/core" prefix="f" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>All Users</title>
</head>
<body>
     <f:view>
          <h:dataTable id="users" value="#{UserBean.users}" var="user">   
            <h:column>
              <f:facet name="header">UserID</f:facet>
               <h:outputText value="#{user.id}"/>
            </h:column>
            <h:column>
              <f:facet name="header">UserName</f:facet>
               <h:outputText value="#{user.userName}"/>
            </h:column>
            <h:column>
              <f:facet name="header">Name</f:facet>
               <h:outputText value="#{user.firstName}"/> <h:outputText 
value="#{user.lastName}"/>
            </h:column>
          </h:dataTable>           
     </f:view>
</body>
</html>

Notice how you bind the dataTable to your Java object. You then simply define the columns of the table, and the component knows to iterate over the rows. This assumes a managed backing bean (UserBean) has been created with your data. The dataTable component creates the HTML for you, so you don't have to specify any HTML for the table. This is one of the advantages of JSF.


JSF and JSP 1.2

JSF has always leveraged JSP technology. However, when it was introduced, JSP 1.2 was the most widely used version of JSP technology. So JSF was based on JSP 1.2, thus JSF didn't support the JSTL and EL. You might have noticed the value attribute of the <h:dataTable> and <h:outputText> tags. These look similar to the EL used by JSTL. However, in JSF 1.0, these looks are literally only skin deep. JSF has its own EL that works a lot like the EL introduced by JSTL, and later made inherent to JSP technology. However, the JSF EL was not compatible with the JSTL EL—until now.

Unified expression language

One of the key points of Java EE 5 is a unified expression language. Thus, the EL used by JSTL and JSF are merged. It's now possible to mix JSTL and JSF, as shown in Listing 8.


Listing 8. JSF and JSTL mix
                
     <f:view>
          <c:forEach items="${UserBean.groups}" var="group">
               ${group.groupName}
               <h:dataTable id="#{group.groupId}" value="#{group.users}" 
   var="user"> 
                 <h:column>
                   <f:facet name="header">UserID</f:facet>
                    ${user.id}
                 </h:column>
                 <h:column>
                   <f:facet name="header">UserName</f:facet>
                    ${user.userName}
                 </h:column>
                 <h:column>
                   <f:facet name="header">Name</f:facet>
                    ${user.firstName} ${user.lastName}"
                 </h:column>
               </h:dataTable>           
          </c:forEach>
     </f:view>

The example in Listing 8 shows multiple groups that are iterated over using JSTL. You then create a display table for each group, listing the users in the group. Notice how the different ELs are used to reference data both for JSTL tags (the <c:forEach>) and as EL expressions directly in the JSP component, as well as for JSF components (the <h:dataTable>). By letting you mix JSTL and JSF ELs, you get the best of both worlds.

EL as part of Java EE 5

There's one other major change for the EL for Java EE 5. A JSTL implementation wasn't required as part of the J2EE 1.4 specification. Web application developers could choose what JSTL implementation to use with their applications. Of course they could also choose to only use a JSF implementation with their applications.

The Java EE 5 specification requires a JSTL implementation. Web application developers no longer have to worry about including an implementation with their applications. Instead, they can use JSTL without any hesitation. They can also leverage the power of JSF. The unified expression language is inherent to this and is part of the Java EE 5 specification.


Geronimo and GlassFish JSTL

The previous section covered the fact that, in the past, Web application developers could choose if they wanted to include JSTL technology. If they did, then it was up to them to pick what JSTL implementation to include with the application. There were various JSTL implementations available to them.

Now with Java EE 5, the JSTL implementation comes with the application server. Thus, any implementation of the Java EE 5 specification must include a JSTL implementation. So when the Apache Geronimo developers started working on their Java EE 5 implementation—Geronimo 2.0—they had to include a JSTL implementation.

However, they couldn't just pick any of the existing implementations. The unified expression language was a major requirement for the JSTL implementation. Many of the JSTL implementations had not been designed to work with JSF. Luckily, the Geronimo team didn't have to implement JSTL and the unified expression language on their own. They were able to leverage Sun's GlassFish.

If you're not familiar with GlassFish, it's Sun's reference implementation of the Java EE 5 specification. It's an open source application, and it's licensed both under Sun's Common Development and Distribution License (CDDL) and the GNU General Public License (GPL). Sun has always provided a reference implementation of JSF, so they were quick to provide a reference implementation of JSTL that included the unified expression language. The open source nature of GlassFish allowed the Geronimo team to leverage this effort and include the GlassFish JSTL implementation with Geronimo 2.0. It was included with the first milestone release for Geronimo: Geronimo 2.0-M1.

Licensing considerations

Because GlassFish is licensed using both the CDDL and GPL, it can be included with Geronimo. However, its license isn't an Apache-style license like the rest of Geronimo, which placed some limitations on the Geronimo team.

Basically, Geronimo includes GlassFish JSTL but doesn't include the source code for it. Further, the Geronimo team can't alter the source code, although they could obviously contribute to GlassFish JSTL, and then package a new binary with Geronimo.

One of the great things about Geronimo is that you can alter its code and distribute your customized version of Geronimo. However, the JSTL implementation is obviously an exception to this. Its source code is not included with Geronimo, and its licensing places limitations on distributing a customized version of it. For example, if you altered the source of GlassFish, your alterations would have to be made available under the same license as GlassFish.


Summary

The evolution of Web technologies in Java technology has greatly benefited developers over the years. The latest evolution, the unified expression language, promises to further benefit developers by allowing them to mix both JSTL and JSF technologies. The unified expression language is now an important part of the Java EE 5 specification, which makes it an important part of Geronimo 2.0. Geronimo has once again helped developers by not only implementing the spec, but by using the reference implementation of the spec. With GlassFish JSTL and Geronimo 2.0, developers have more choices than ever when building Java Web applications.


Resources

Learn

Get products and technologies

Discuss

About the author

Michael Galpin's photo

Michael Galpin has been developing Java software professionally since 1998. He holds a degree in mathematics from the California Institute of Technology and currently works at Adomo, Inc.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Java technology, WebSphere
ArticleID=252005
ArticleTitle=The Geronimo renegade: Using integrated packages: GlassFish JSTL 1.2 and Apache Geronimo 2.0
publish-date=08282007
author1-email=mike.sr@gmail.com
author1-email-cc=ruterbo@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers