• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Query string question

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that gets the parameters from a query string. The parameters are then dipslayed in a jsp, however, in the jsp, I need to pass the same parameters to the next jsp page. I tried storing the parameters in the httpsession in the servlet that I use, the first time the query string is passed, the problem is, the session no longer exist when the first jsp page is displayed. Any suggestions on the parameters appropriately? Thank you.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how navigation is happening from one JSP to another? i think this should be stored as request attribute.
 
Edward Manalansan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the sequence..
1. Query string is http....\servlet1?param1=test
2. In servlet1, I store param1 using httpsession, then displays param1 in jsp1(no issues) using Requestdispatcher.
3. Jsp1 uses form action = servlet2, in servlet2 when I issue..

GISAddress gisaddress = (GISAddress) request.getAttribute("gisaddress");

gisaddress.getParam1();

it is null.

I used the same GISAddress in jsp1 and it is working, somehow GISAddress is gettting destroyed prior or when servlet2 is fired.

Thank you.
 
Marshal
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you be looking for a session scoped variable in the request?

GISAddress gisaddress = (GISAddress) request.getAttribute("gisaddress");


 
Rajeev roushan sharma
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Edward Manalansan wrote:Here is the sequence..
1. Query string is http....\servlet1?param1=test
2. In servlet1, I store param1 using httpsession, then displays param1 in jsp1(no issues) using Requestdispatcher.
3. Jsp1 uses form action = servlet2, in servlet2 when I issue..

GISAddress gisaddress = (GISAddress) request.getAttribute("gisaddress");

gisaddress.getParam1();

it is null.

I used the same GISAddress in jsp1 and it is working, somehow GISAddress is gettting destroyed prior or when servlet2 is fired.

Thank you.




Hey Edward, No need to use session and all in your scenario. If you are using the RequestDispather to forward to your JSP then you will get the same request in your JSP too. so you can simply write request.getParameter("param1") and your are done!
 
Bear Bibeault
Marshal
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rajeev roushan sharma wrote:Hey Edward, No need to use session and all in your scenario. If you are using the RequestDispather to forward to your JSP then you will get the same request in your JSP too. so you can simply write request.getParameter("param1") and your are done!


That will not work in his scenario as the data needs to be available across multiple JSPs as per his original post.
 
Rajeev roushan sharma
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Rajeev roushan sharma wrote:Hey Edward, No need to use session and all in your scenario. If you are using the RequestDispather to forward to your JSP then you will get the same request in your JSP too. so you can simply write request.getParameter("param1") and your are done!


That will not work in his scenario as the data needs to be available across multiple JSPs as per his original post.


You can use the same request querystring with your link..

 
Bear Bibeault
Marshal
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rajeev roushan sharma wrote:You can use the same request querystring with your link..


Why go through all the hassle of reconstructing query stings when the session is so much easier and the appropriate choice?
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Edward Manalansan..

Welcome to JavaRanch.

Real problem is you are setting attribute in Session but at the time of getting it you are getting it from HttpRequest object because of which it is coming as null.
As HttpRequest object doesn't know anything about session.

So you have to use


Then only it will display the value of "gisaddress".

 
Edward Manalansan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear and Shanky, thank you so much. Both of you are absolutely correct, when I replaced request with session, the desired result is met.

The way this application starts is by receiving a query string with parameters passed from a .net application, this is the only part where it uses query string, I use session all throughout the application.

Again, I couldn't be more thankful for all who responded.

Best regards.
 
mooooooo ..... tiny ad ....
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic