aspose file tools
The moose likes Servlets and the fly likes Query string question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Query string question" Watch "Query string question" New topic
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
    
  13

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
    
  13

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
    
  13

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Query string question
 
Similar Threads
Passing parameter to a popup window in JSF
How does servlet know which url to open?
how to get the values in a servlet? the values are set in a bean using jsp
what is the attribute in servlet ?
Invoke JSP from Servlet