It's not a secret anymore!
The moose likes Struts and the fly likes Form Variables vs Session Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Form Variables vs Session Variables" Watch "Form Variables vs Session Variables" New topic

Form Variables vs Session Variables

Pavan Kumar

Joined: Jun 08, 2005
Posts: 23

Can anyone tell me whether its better to use Action form variables or variables in session when we want to transfer data between Action class and JSP? Also please list the advantages of using either one of them.
Thanks in advance.

- Pavan.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
What Action form variables??? Are you talking about Struts here?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Pavan Kumar

Joined: Jun 08, 2005
Posts: 23
I meant Struts Action Form.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I prefer to use variables defined on my action form. At a minimum this gives the JSP developer a place to look up the name of the properties. Also, if I had a value in my Action that I needed to display on my jsp I would store it in the request before I stored it in session.

- Brent
Manuel Jordan
Ranch Hand

Joined: Sep 29, 2006
Posts: 131

well a normal ActionForm or ValidatorForm is like a pojo, all the simple variables should be type String , the common scope is request

but you can create special variables with scope session before load a jsp
(maybe a list for a html:select), why?, because if you working with validation and detects any error, its create a new request and lost the variable that represents a List, of course that you have a variable or property that represents the value selected of the List (i had this problem if i dont use session scope for the list)

if exist another better way, please let me know

[ October 08, 2006: Message edited by: Manuel Jordan ]

kill your pride, share your knowledge with all
I agree. Here's the link:
subject: Form Variables vs Session Variables
jQuery in Action, 3rd edition