Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query string question

 
Edward Manalansan
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.
 
Rajeev roushan sharma
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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?
 
Shanky Sohar
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic