This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session usage in struts

 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use session in struts, is it OK if I keep set scope="request" in the <action> tag, and in each Action class I write "HttpSession session = request.getSession(); session.setAttribute("key", "value");" ? The reason is I don't want to set so many forms in the session because I don't need all of the information stored in the form. I will selectively store some useful objects in the session. Is this approach OK ? or do I have to set scope="session" as a must-do ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Artemesia,
This is fine. It sounds like you recognize that you want the forms in the request while other info should be available everywhere (aka in the session.) This is common for things like a username.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Artemesia,
This is fine. It sounds like you recognize that you want the forms in the request while other info should be available everywhere (aka in the session.) This is common for things like a username.



actually, another reason why I prefer to set "scope=request" for each <action> tag is --- everytime when I need to get a specific variable in my action business method, I need to retrieve that form first and then get the field, tedious.

Two more question I want to confirm --

1. Is I use session in the Action class, I should use "URL encode" for the "action=" part in the JSP's pages' <FORM action=".."> . Right ? I don't need to change anything or worry about the "path=/myJSp" part, right ?
if we use "scope=session' for every "action" in struts-config.xml

2. Assume I set "scope=session" in the struts-config.xml, if I have the following scenario --

On Page1, pick choice a), go to Register.jsp, then go to Checkout.jsp
On Page1, pick choice b), go to Checkout.jsp, then go to view.jsp

if I go through the first path to Checkout.jsp, and then click back to Page1 and start the second, when I get to Checkout.jsp, this time the "CheckoutForm" stored in the session will be replaced by the current one, right ? i.e. the "FormBean" stored in the session can be replaced everytime user pick different things and resubmit, as long as the session is being valid. AM I right ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic