This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Problem getting attributes from request in Struts2
Sammy Bill
Ranch Hand
Joined: Dec 29, 2008
Posts: 96
posted
0
Hello,
In my action when i set an attribute in the request object i can not retrieve it from the jsp, but when i put it in the session, i m able to retrieve it.
how can i set the request attribute in my action to use it in the jsp.
and when i do <%=request.getAttribute("catalog")%> it prints null.
it works fine.
Which is it?
That aside, you're doing two different things: you're accessing the session in the JSP via an action property (which is fine, but a little weird). You're accessing the request via JSTL's normal implicit object. Whether or not you *should* be storing this data in the request or session is debatable--personally it seems like it belongs in either the application scope or in no scope at all and should be exposed via an action property.
Note also that it's *much* cleaner to implement RequestAware to get the request's attribute maps, and has the benefit of not tying your action to the servlet spec.
Lastly, without knowing the result type it's hard to say--I would have thought a standard "dispatcher" result type would have worked.
Sammy Bill
Ranch Hand
Joined: Dec 29, 2008
Posts: 96
posted
0
David Newton wrote:
That aside, you're doing two different things: you're accessing the session in the JSP via an action property (which is fine, but a little weird). You're accessing the request via JSTL's normal implicit object. Whether or not you *should* be storing this data in the request or session is debatable--personally it seems like it belongs in either the application scope or in no scope at all and should be exposed via an action property.
Note also that it's *much* cleaner to implement RequestAware to get the request's attribute maps, and has the benefit of not tying your action to the servlet spec.
Lastly, without knowing the result type it's hard to say--I would have thought a standard "dispatcher" result type would have worked.
i Tried to implement the RequestAware interface but i still can not access the request attributes from the jsp page while i can access the object if i store it in the session