Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

session usage in struts

 
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 ?
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • 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 ?
    Bookmark Topic Watch Topic
  • New Topic