Solved

Usage of Scope in Struts

Posted on 2004-10-06
6
9,425 Views
Last Modified: 2008-09-17
Hi,
   I am a little confused with when to use session and request scope for the forms when using Struts. I do know that session and request scope means. Can anyone please help me on this??

Thank you,
Stephen
0
Comment
Question by:JohnyStephen
  • 3
  • 2
6 Comments
 
LVL 32

Accepted Solution

by:
ldbkutty earned 25 total points
ID: 12246692
Its the same as the general understanding of "session" and "request". If you set scope="session" in your config file,
the variables and the methods of the form-bean is accessible to all the pages. If scope="request", its accessible only to the next page and not to the other pages. For example, user information of course makes sense to store in the session since you may have to pull that out in numerous places, but a list that is simply used to supply options for a drop down list on one page in a huge application does not need to persist throughout the whole user’s session(so "request" scope should be enough).
0
 
LVL 14

Assisted Solution

by:boonleng
boonleng earned 25 total points
ID: 12248030
Additional info:
"session" and "request" scope also behave a bit different. In scope "request" struts will call the method reset() of the form bean each time the action is performed, whereas scope "session" wont do reset automatically.
0
 
LVL 14

Expert Comment

by:boonleng
ID: 12248117
If you have a form split across several pages, then is better to use "session" scope, data in form bean can be stored in session and pass through pages. (best not to use hidden field to pass value across pages as it will raise security issue).
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:JohnyStephen
ID: 12256387
HI,
  Thanks for all the replies, but I have a doubt, In some places where dynavalidatorforms are used and if a form property is of type array  <form-property name="interests" type="java.lang.String[]" initial="null"/> (displaying dynamic fields), and then if I want to take the values back into the form when I sbmit, i read somewhere that the form should be session scoped and not request scoped, otherwise it won't be able to take the dynamic values. Can someone please explain this?

One more thing,
boonleng ,
U said if I use session scope for the bean the reset() method won't be called automatically, but I found that the reset() was getting called everytime, though it didn't have any effect on the form values. Even though i tried to set the values in the reset method, they were reverted back to the old values !!! :o(


Thanks,
Stephen
0
 
LVL 14

Expert Comment

by:boonleng
ID: 12273501
opps... sorry... my mistake :p

Actually both scope call the reset() method automatically, just that for scope "request", struts will create a new intance of the formbean for each new request, so you dont need to overwirte the reset() method to set the value back to default. For scope "session", you will need to overwrite the reset() method.

Coz struts create new formbean for each request, so you wont be able to get back the dynamic value once you click submit or hit struts validator error. You can either use scope "session" for the form bean or store the dynamic value in http session seperate from form bean.
0
 

Author Comment

by:JohnyStephen
ID: 12296338
Hi , I am not sure I got the answer I wanted, but I guess my question was also vague, and I got good answers for that. So I am splitting the points. Thanks guys, for your help.

Stephen
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ajax auto save 15 98
default methods vs abstract class 1 109
Getting NoSuchMethodError on accessing a spring mvc project 3 158
How to Post an If Statement in JSP 3 51
Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now