File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes session usage in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "session usage in struts" Watch "session usage in struts" New topic
Author

session usage in struts

Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
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

Joined: May 26, 2003
Posts: 30749
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
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 ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session usage in struts