| Author |
Query string question
|
Edward Manalansan
Greenhorn
Joined: Apr 01, 2011
Posts: 4
|
|
|
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.
|
 |
Rajeev roushan sharma
Ranch Hand
Joined: Jan 28, 2010
Posts: 50
|
|
|
how navigation is happening from one JSP to another? i think this should be stored as request attribute.
|
 |
Edward Manalansan
Greenhorn
Joined: Apr 01, 2011
Posts: 4
|
|
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.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
Why would you be looking for a session scoped variable in the request?
GISAddress gisaddress = (GISAddress) request.getAttribute("gisaddress");
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Rajeev roushan sharma
Ranch Hand
Joined: Jan 28, 2010
Posts: 50
|
|
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
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
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
Joined: Jan 28, 2010
Posts: 50
|
|
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
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
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?
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
@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".
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Edward Manalansan
Greenhorn
Joined: Apr 01, 2011
Posts: 4
|
|
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.
|
 |
 |
|
|
subject: Query string question
|
|
|