Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^^
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?
 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^^
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value stack is in scope, and the action is on the value stack.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic