Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Struts2 and how data is passed

Status
Not open for further replies.

fahlen

Programmer
Nov 28, 2006
5
ES
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.

Thanks.
 
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.
 
Thanks for your reply! I'll give it a try.
 
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!
 
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
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top