• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use httprequest object through out the application

 
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....


kaustubh
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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........

kaustubh
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to say that once I set all the values in the request whereever I create the HttpRequest's object from there I can extract the same values???
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. You shouldn't place any of those objects into the request - they should go into the user's session.

Please restrict yourself to a single question mark at the end of a question; it's sufficient.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in case If i create a new object of HttpServletRequest in other class did I get the same values which I set in different class?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry It was a mistake I was talking about HttpSession object will it be work if i create a new one on other side of the application...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't *need* to create a new one (and if you did, it would be just that--a new session. You want the *existing* session.)
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Regards
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
gotcha thank you guys for your help and support.....

kaustubh:)
reply
    Bookmark Topic Watch Topic
  • New Topic