# InfoQ Article: Migrating Struts Apps to Struts 2 - Part III

| by Floyd Marinescu 28 Followers on Dec 05, 2006. Estimated reading time: less than one minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

In this third and final part of the Struts 2 migration series, Struts committer Ian Roughely completes the migration of a Struts app to Struts 2, by migrating the user interface - jsps & tags. From a high level, many of the tags in Struts2 are going to look very similar to those that are present in Struts.  There are tags for logic, tags to present data from beans, and tags that assist with forms and populating bean data into specific fields.  It is only when you take a closer look, that the differences become apparent.

Read Migrating to Struts 2 - Part III

After reading this article series,  you should understand the Struts2 architecture (both the overall and the user interface architecture); be able to explain the differences in request processing; understand how to configure a Struts2 application; and know how to combine actions and JSP’s.

Rate this Article

Adoption Stage
Style

## Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

## Get the most out of the InfoQ experience.

### Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

JSTL Integration

The syntax being suggested here seems verbose, and requires the user to differentiate between request scope and value stack.

Where the author suggests:
       <tr>           <td align="right">Id:</td>           <td><s:property value="id" /></td>       </tr>       <s:textfield label="Title" name="title" value="%{title}"/>

I simply use the built-in JSTL Integration in Webwork 2 to write:
       <tr>           <td align="right">Id:</td>           <td>${id}</td> </tr> <s:textfield label="Title" name="title" value="${title}"/>

This also relieves me of a dependency on OGNL.

Is the JSTL integration not supported in Struts 2, or is the author just using the cumbersome notation for illustrative purposes?

Re: JSTL Integration

Is the JSTL integration not supported in Struts 2, or is the author just using the cumbersome notation for illustrative purposes?

Struts 2 continues the same support WebWork 2 had for JSTL, as smooth JSP, JSTL, and JSF integration is a top priority.

Freemarker

You only briefly mention it, and I understand this is migration guide, but I would strongly suggest considering both Freemarker and Velocity for the views before beginning simply translating all your views using the JSP tags.

Re: Freemarker

Freemarker and velocity are great technologies for the view. In this article I was taking the stance of an application starting with JSP and ending with JSP.

Re: JSTL Integration

The syntax being suggested here seems verbose, and requires the user to differentiate between request scope and value stack.

Not sure what you are specifically talking about. Using the property tag searches the value stack which includes the request (as a named object). There is an option to select the request directly, but it is not necessary.

Is the JSTL integration not supported in Struts 2, or is the author just using the cumbersome notation for illustrative purposes?

Don answered the first part. Regarding the second - I was illustrating the pure struts2 tag library example. There are many ways to mix and match techniques in struts2, my goal was to keep things simple for this article.

Re: JSTL Integration

Not sure what you are specifically talking about. Using the property tag searches the value stack which includes the request (as a named object).

Using the (briefer) JSTL notation I described above also searches the value stack which includes the request.

Re: JSTL Integration

ok - so yes, you wouldn't need to specify the request scope for Struts2 JSTL. However, because we are migrating an application from Struts to Struts2 and Struts has no concept of a Value Stack we would need to have it specified in the original JSPs.

If the article was presenting JSTL as the final view markup rather than the Struts2 tag libs, the JSTL could have then been simplified.

Re: JSTL Integration

Actually I'm not sure that you are right about
Struts has no concept of a Value Stack we would need to have it specified in the original JSPs.

As I know it has. F.e. all tags that have scope attribute have option don't specifiy it. If the scope attribute is not specified, then the tag will search for the bean in the scopes in the order of page, request, session, and application. Or this is not a Value Stack?

Re: JSTL Integration

In a non-Struts2-integrated JSTL you may be able to use "blog.title" as the expression (having it search the scopes you listed), but not the simple "title" from the original Stuts2 example - which would require it to know about the action as a first class scope.

Problem running example

I downloaded the blog example in this article and was able to run it on Tomcat 5.5.20.

1. When I edit a blog entry and click on "Update" button, I saw these error messages in the Tomcat log file:

"SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception catched: Error setting expression 'entry' with value '[Ljava.lang.String;@8eae04'"

SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception catched: Error setting expression 'title' with value '[Ljava.lang.String;@1531164'

2. When I click on the "Back to List" link I see these error message in tomcat log:

SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception catched: Error setting expression 'id' with value '[Ljava.lang.String;@6127da'

----------------------------------------

Did anyone else have this problem? I have used Struts1 but
new to Struts2.

Re: Problem running example

I too get that ParametersInterceptor.setParameters(204) error when trying to get values from a multiple select combo. Earlier it used to work, but suddenly it broke. Any ideas on this???

JSTL Integration

Why use S2 tags/OGNL over JSTL?

Scott

some doubts

hi
i have a jsp named "displayEmployeeRecords.jsp"

which should display the list of employee details like name , empid , salary

i have implemeted this in struts1.2.

i have implemented the action class and other xml files .

i have a Arraylist object which contains a list of EmployeeModel object

1)if Arraylist is empty then the action class should be called
to populate the ArrayList
else the ArrayList should be iterated to display its content
2)tell me how to display this using struts2.0

i have done this in struts 1.2 but i dont know how to call a Action class

in Struts1.2-> /EmployeeData.do -> will call the Action class
in Strut22.0->?

in struts 1.2 -> logic:iterate to iterate the ArrayList and display the data
in strut2.0->?

Re: Problem running example

You are using devMode, that's why. Disable devMode in struts.properties or in struts.xml, it is just to inform you, when made some misstypo, when developing the application.

Re: method invocation - contains

Hi, I have the following problem:
I have a list of reports and I'm using <s:iterator > to show it on the screen and it works fine. But I also have another list with "bad" reports, and while iterating over reports list I need to check if bad reports list contains current report.
Here is what I want to have():

<s:iterator value="reports">

<s:if test="badReports.contains(report)">// Can I write expression like this or something similar

It's bad report

</s:if>

<s:else>

Good report

</s:else>

</s:iterator>

Can you explain how I can solve this?
</s:iterator>

How to make local struts.properties

How can I a make a local struts.properties file? I need that because I want to use modes like devMode in development environment but not in production. So I could in this situation make a local struts.properties file and put it on cvsingore list.

How to migrate logic:equal, logic:present in Struts2

Hi,
I am new to Struts2 and currently working on Struts1.x to Struts2 migration. I need to change logic:equal and logic:present tags in the Jsp. Here is the problem I am facing:

STConstants.java has some constants such as:
public static final string ALT_PBR = "fusion";

Customer.java is a POJO having the following fields with getters and setters:
firstname, lastname,addressline1,addressline2,city,state,postalCode

In NewCmpAction.java we have:
Customer cust = new Customer();
//code which sets all the fields in cust object
.
.
//cust object is placed in session
session.put(STConstants.ALT_PBR,cust);

In slsDetail.jsp, I want to check if "cust" objects exists in session, if it exists then if the value of city field in "cust" object is equal to "CA".
In Struts 1.x we used logic:equal and logic:present but in Struts2 we do not have logic:equal and logic:present and I assume we have to implement this logic using if tag. I tried various combination but it didnt work.
I know if I use #session.fusion.city I will get the city value which I can compare to "CA" but I want to get the value "fusion" by referring to STConstants.ALT_PBR in the jsp. How can I do that? For eg: #session.???.city where ??? = STConstants.ALT_PBR.

Please help.
Also, how can I check if session has "cust" object? or how can I check if it is not present in session.

Re: How to make local struts.properties

You can create a file with name "struts.properties" and put it in your source folder and then set devMode accordingly.

other technologies used with struts 2

i want to know when the struts 2 framework was released? Means in which year struts 2 was the first choice for developing java web applications. What other java technologies are at the boom with struts 2???
Please reply soon on kheralalit@gmail.com
Close

#### by

on

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

19 Discuss

Login to InfoQ to interact with what matters most to you.

Recover your password...

#### Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

#### More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

#### Stay up-to-date

Set up your notifications and don't miss out on content that matters to you