aspose file tools*
The moose likes Struts and the fly likes Struts 2 - Getting values from action in JSP pages using scriplet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 - Getting values from action in JSP pages using scriplet?" Watch "Struts 2 - Getting values from action in JSP pages using scriplet?" New topic
Author

Struts 2 - Getting values from action in JSP pages using scriplet?

Swerrgy Smith
Ranch Hand

Joined: Mar 26, 2010
Posts: 91
Dear all,

I have a property in an action class. How can I get its value in JSP pages without using Struts tag (like s:property etc.)?
For example, how can I print it value using scriplet like this: <% String s = request.getAttribute("myAttribute"); out.println("This is my string " + s); %>

I tried this code but it doesn't work. In which scope (request, session, application ...) is my property stocked?

Thank you very much.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

^^
If you redirect the page, then a new request would be passed as a result. You better try with session scope. And i didn't know why you wanna use ugly scriptlets inside JSP?


Never try to be a hard-worker. Be a smart-worker.
My Blog
Swerrgy Smith
Ranch Hand

Joined: Mar 26, 2010
Posts: 91
Rajkumar balakrishnan wrote:^^
If you redirect the page, then a new request would be passed as a result. You better try with session scope. And i didn't know why you wanna use ugly scriptlets inside JSP?


Dear Rajkumar,

Thank you very much. I just want to try another method. Furthermore, I don't understand how this property is pass from action class to JSP page? In which scope is it stocked (request, session, application ...) ?

Thank you very much.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

^^
I think you would probably specified that in your struts-config.xml file. If not, then

the default scope is request. Btw, the scope is for the ActionForm (@ Form Bean) associated with the Action, not for the Action itself.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Rajkumar balakrishnan wrote:
I think you would probably specified that in your struts-config.xml file. If not, then

the default scope is request. Btw, the scope is for the ActionForm (@ Form Bean) associated with the Action, not for the Action itself.

You are answering for Struts 1; the question was regarding Struts 2.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Get a reference to the value stack, it's in the request.

I don't know why you'd want to do this either, but that's what you'd need to do.
Swerrgy Smith
Ranch Hand

Joined: Mar 26, 2010
Posts: 91
David Newton wrote:Get a reference to the value stack, it's in the request.

I don't know why you'd want to do this either, but that's what you'd need to do.


Hello David,

Does that mean the property is neither in request, nor in session/application scope?
(I used to think that every object must be stored in request/session/application scope.)

Thank you very much.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The value stack is in scope, and the action is on the value stack.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts 2 - Getting values from action in JSP pages using scriplet?