This page contains FAQ on Struts, Struts-EL, JSTL and Ajax tags. The separation between these categories is rather fluid, because it is possible to mix and match tags, for example to use JSTL tags or scriptlets within Struts tags. Therefore, please look in all categories.

Struts tags

Using the <html:link> tag for multiple, dynamic parameters

Well, there seems to be a lot of frustration and discussion about this "standard" requirement in web applications. Most web applications want to use multiple, dynamic url parameters in their links, but currently it seems like the only official way breaks with anti-scriptlet rule.

For a discussion, please read:

Here comes the solution with JSTL...

<c:url value="/" var="url">
<c:param name="param1" value="${user.fullName}"/>
<c:param name="param2" value="${'parameter 2'}"/>
<a href="${url}">Click</a>

NPE when accessing value using scriptlet

Q: I use the following code in a jsp:

 <logic:present name="person">
   <html:text property="name" " value='<%= person.getName() %>'/>

If 'person' is not present <%= person.getName() %> is compiled and I get this error: membreLIFL cannot be resolved

If i use this code:

 <logic:present name="person">
   <input type="text" name="name" 
          value="<bean:write name="person" property="name"/>"

No problem. How can i use the html:text tag?

A: JSP scriptlet is a regular Java code, which calls a method on "person" object. If "person" object is not defined, an NPE is generated.

Choice 1: If you use JSP 2.3 + Struts-EL or JSP 2.4, you can use the following syntax to access "name" property:

 <html-el:text property="name" value="${}" />

JSTL does not throw NPE if you accessing a property of non-existing object.

Choice 2: If a Struts tag defines "value" attribute, it is possible to use either this attribute or text element of a tag. The following definitions are equivalent:

 <html:text property="name" value="someData"/>


 <html:text property="name">

Struts-EL tags

JSTL tags

Comparison using nested tag vs JSTL for nested objects on form

Many think that you are required to display nested data using the Nested tag. I agree the Nested tag is the cleaner solution, but just so you are aware you can do this with JSTL as well. (Below assumes JSP2.0)

companyForm has a List of divisions and for each division in the list there is a list of department objects and we will display the 'name' of each department.

JSTL Solution

<c:forEach items="${companyForm.divisions}" var="division" varStatus="divstatus">
    Division: <html:text property="divisions[${divstatus.index}].name" value="${}" /><br>
    <c:forEach items="${division.departments}" var="department" varStatus="depstatus">
    --- Department: <html:text property="divisions[${divstatus.index}].departments[${depstatus.index}].name" value="${}" /><br>

Nested Tag Solution

<nested:root name="companyForm">
  <nested:iterate property="divisions">
    Division: <nested:text property="name" /><br>
        <nested:iterate property="departments">
        --- Department: <nested:text property="name" /><br>

JSP scriptlets

Ajax Tags

AjaxTags is an enhanced version of the standard Struts HTML taglibs that provides an easy way to add AJAX functionality to an existing struts app through a completely declarative approach (read: it's all an XML config file). This enhanced taglib provides 100% compatibility with the normal HTML taglib and in fact requires NO changes to existing pages UNTIL you want to add AJAX functions.

The original AjaxTags project, which is still available on the Struts Apps SourceForge page at is **DEPRECATED** in favor of the AjaxTags subcomponent of the Java Web Parts (JWP) project at AjaxTags in JWP is a much more powerful and flexible version of the original concept and IS NOT STRUTS-SPECIFIC like the original was. While the original version is still available, it is no longer being developed and will likely NOT work with future Struts versions.

It is HIGHLY recommended that the AjaxTags in JWP be used if this is something you are interested in as you will definitely find it more feature-rich and just as easy to use, and it IS being supported and further developed (I will still support the original version as much as I can, but at a lower priority than the version in JWP).

  • No labels