Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Struts2 and how data is passed

Struts2 and how data is passed

Struts2 and how data is passed

Hi! I'm new to Struts and have a question regarding how data can/should be passed between an action (extending ActionSupport) and the JavaServer page to which one is then redirected (according to the mapping done in the struts config file).

Should I explicitly store the action/JavaBean in the session object (from the action file) and then retrieve it from the JSP to which I'm redirected?. I've been reading the Struts 2.x documentation, but I can't quite wrap my head around it.

Or is there a Struts tag which can/should be used for this purpose, i.e. to access the fields/getter methods of a bean? The s:property tag for example? What I'm wondering is if the action/bean object is implicitly made available to the JSP by the framework, and can be accessed using a Struts tag.

Any input would be greatly appreciated.


RE: Struts2 and how data is passed

if the data has inputted in a form which captured by actionform,this actionform can be accessed in request or session scope.in struts-config file while you writing the action mapping you need to mention the scope of form(acts as DAO) so you can access in jsp by via bean getter and setters in the form.

RE: Struts2 and how data is passed

Thanks for your reply! I'll give it a try.

RE: Struts2 and how data is passed

Looking at it more closely, I think the scope parameter exists only for the struts-config.xml file in Struts 1.x, but not for struts.xml in Struts 2.x. I could be mistaken. Could you confirm if this is the case? Unless I'm mistaken, how would one go about defining the scope for the action class (extending ActionSupport) so that the object and its getter/setter methods are available in the JSP-pages, using Struts tags?

Thanks again!

RE: Struts2 and how data is passed

Me again... I've found that using the Scope Interceptor one can specify Action properties to be bound to the session or application scope. This is done in struts.xml within the action tags. See http://www.twdata.org/backups/WW/scope-interceptor.html

Say I access an EJB from an Action. The method of the EJB returns some data. Is it good programming practice (in Struts) to store this data in the session object, later to be accessed from a JSP? This should allow me to pass the data, but perhaps there is some other alternative which is preferred. Storing information in the session object would maybe be good for data such as UserID, contents of a shopping cart, etc. The scope I believe I am interested in is request scope.

Would the preferred method then be to implement ServletRequestAware interface in the Action and store data of interest in the request object? Because I can't find any interceptor that does this. I'm sure one can also create user defined interceptors, but if there's a standard method for this provided by the framework, then I guess that would be the preferred way to go.

I'm grateful for any input on the matter. Cheers.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close