This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Passing attributes from servlet to jsp  RSS feed

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a situation where from the first jsp i am invoking servlets do post method with a ajax and getting some text data to first jsp, at the same time i want to make some objects available to 1 st as well as another (2nd ) jsp page.what i am thinking is to set this attribute in session scope and then i get them in any jsp i want but i want to whether its is possible to do this and if possible then can you show me with little code example.I am new to web technology.
Thanks
Sruthi
 
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing what the relationship between the first and second JSP pages is, impossible to say anything.
 
sruthi reddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
second jsp page will be called from first jsp with href.there will links in the first jsp and with click on link second jsp will open.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so this is no different than any other scenario where data from one page needs to made available to another. Either the data is included as part of the submission data, or is stored as scoped variables in the session. Pick whichever one makes the most sense.
 
sruthi reddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya this is pretty much same senario but the thing is i want data from servlet to use in second jsp, not from first jsp to second jsp. so this still work for this situation and also when i set attributes in session scope, do i need to forward page using request dispatcher. as i already told, i am using ajax to call do post of servlet and i am getting data to first jsp as ajax response. so right now i am not forwarding to any page as it works fine for me. give me your suggestion as how to approach
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The session sounds like the best bet for your scenario. be sure to clean up the scoped variables when they are no longer needed.
 
sruthi reddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used session as well as context attributes to test my situation and i am getting null values when i am using for the first request and then for sebsequent requests , i am getting my actual values. so can suggest me something so that i am able to get values for the first request.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If nothing has set values into the session for the first request, why should you expect anything to be there?
 
sruthi reddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i understand the situation. anyway i was testing this in my first jsp for the frist request, its going to be null.So my question is after making the first request from my first jsp, i can use set values in my second jsp if user clicks the link in my first jsp.is it possible or still the values wont be set.
 
sruthi reddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear Bibeault
I think my problem is solved for now.Thanks for your suggestions
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!