Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

3.2. Using the Struts-EL Tags

Problem

You want to be able to use JSTL expressions for attribute values on Struts tags.

Solution

Use the tag libraries supplied with the Struts distribution in the contrib/struts-el/lib directory. You will need to copy all the JAR and TLD files from this directory to your application's WEB-INF/lib directory. Use the appropriate taglib directives on JSP pages where you want to use expressions:

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el" 
        prefix="html-el" %>

Table 3-2 lists the Struts-EL tag libraries and the corresponding taglib URIs.

Discussion

JSTL-style expressions, such as ${foo.bar[4].baz}, are not supported by the base Struts tags. For example, it would be nice if you could format a tag using an expression like the following:

<html:text value="${sessionScope.foo.bar[3]}"/>

Instead, these tags require runtime expressions, which is just Java code:

<html:text 
    value="<%=session.((Foo)getAttribute("foo")).getBar(3)%>"/>

Getting the Java code out of your JSP pages makes your pages less brittle and more maintainable. This lack of EL support was identified ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page