hi i am working with struts 1.3 from one of my action I am setting some values into my request object e.g. the name of the user. Now I want to use the same request throughout my application and I can not pass this request to other method because till I used in other part the values from the request lost.I know about ServletConfig and ServletSontext can i use it here or is there any other option available plus when I created a new HttpRequest object on different page does it affect the old request...??
please sort out the above doubts if you get it or asked me to clear it more.....
Data that needs to be carried around the app for a specific user should be put in the *session*. The request is recreated for every request, as the name implies.
Chankya Sharma
Greenhorn
Joined: May 20, 2010
Posts: 1
posted
0
I agree with David, if you want to keep the data accessible every where for a user than you need to put in a Session. You can also do this through the form files and set the scope of the file to Session in struts-config. Than you just need to get the form file and fetch the data from it where ever you want.
An action form isn't an appropriate place for non-Struts-specific information like user data; that should just be stored in the session by itself (or as part of an application-specific session data object).
I know about the session sir but and when I set everything into it I have to pass it into method I wanted to use it.But I need a solution from where I can use this values through out my application without passing it to the method because I have to change lot of places where the method is used........
If it's in the session you don't have to pass it anywhere--it's available anywhere the session is.
If you're saying you want to abstract it out of the session then create a composite object containing the session objects you want to pass and pass that into your methods; if the data contained in the composite object changes you'd have to change your methods anyway.
Of course not--you'll have just created a new request object. But you're still talking about request, while we're talking about session--so something's getting misunderstood.
Then everytime I have to pass this session object everywhere in my application. What if I want to do it as a centralize object where it can be used by every servlet and jsp?
kaustubh
Glen Divers
Ranch Hand
Joined: Jan 21, 2010
Posts: 61
posted
0
Kaustubh G Sharma wrote:Then everytime I have to pass this session object everywhere in my application.
Struts handles this for you - all you have to do is access the session object where you need it.
Kaustubh G Sharma wrote:
What if I want to do it as a centralize object where it can be used by every servlet and jsp?
kaustubh
If you have a "global" object, store it in the Application Context.