This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts 2: Action objects not passed to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2: Action objects not passed to JSP" Watch "Struts 2: Action objects not passed to JSP" New topic

Struts 2: Action objects not passed to JSP

Jonathan Su

Joined: Aug 23, 2007
Posts: 4
I am building a web application using Struts 2 when I come across a seem-to-be weird problem.

Well defined object attributes in action class sometimes cannot not be passed to JSP. But sometimes it works just fine and everything shows in JSP corretly.

It happens very radomly and I really cannot tell the pattern.

I have made sure that before the action return 'SUCCESS' the objects are still there, whereas on the jsp side, they turn into nulls.

The following is section of my struts.xml:

<action name="launch" class="" >
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="inputValidator"/>
<result name="success">jsp/MemberInquiry.jsp</result>
<result name="error">jsp/error.jsp</result>
<result name="new_member" type="chain">preprocess</result>

Do I need to define the object type in struts.xml or somewhere else?

Any help would greatly appreciated!!

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm afraid we don't have enough information to be of much help. Could you please post relevant portions of your MemberInquiryAction class and JSP?

Consultant, Sima Solutions
Jonathan Su

Joined: Aug 23, 2007
Posts: 4
Here is my scenario in more detail:

Class AbcActionBean extends ActionSupport {
protected MemberEntity member; //MemberEntity is defined in Entity package.
with public getter and setter.

Class MemberInquiryAction extends AbcBean {
execute() {
member is populated from DB.
// at this point member is still populated
return SUCCESS;

In JSP side, I am trying to display member info like this
<input type="text" name="member.firstName" value"${member.firstName}"/>
or directly, <td>${member.age}</td>

For debug purpose I display ${member} on the screen just to see if the object is there.

Very randomly when the jsp is display the member object become null and obviously no attribute of it would show. If I repeat the same action it would show again.

Please help.

Jonathan Su

Joined: Aug 23, 2007
Posts: 4
One thing I notice is that only the types I defined in the application have this problem. String, ArrayList (although has custom-defined components), int, float etc, can be passed without any issue.
I agree. Here's the link:
subject: Struts 2: Action objects not passed to JSP
It's not a secret anymore!