Get your CodeRanch badge!*
The moose likes JSP and the fly likes how to add data in request object and pass it to next page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to add data in request object and pass it to next page?" Watch "how to add data in request object and pass it to next page?" New topic
Author

how to add data in request object and pass it to next page?

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
I am in JSP page a.jsp, its has one hyper link on it, My intention is I have to some data in request object and pass it to next page ,

when I click on the hyperlink, I should navigate to Next JSP b.jsp, there I will get the same data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

No can do. The two JSPs exist in separate requests so they cannot share data. The request that generates the first HTML page from the first JSP goes out of scope as soon as the response is sent to the browser. Any scoped variables created on that request go by-by with the request.

If you want to preserve some data across requests you'll either need to store it in the session, or carry it on the page as hidden values (suitable only for text strings).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


request object 's scope belongs to Server and hyperlink is just a link in Client browser. So it is possible only when you pass request object's value in the hyperlink as query string .

<!a href="/web/app?value=one"> like this
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
carry it on the page as hidden values (suitable only for text strings).


it is really very interesting ,could please give some code or explain in details will help me lot
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
<input type="hidden" name="whatever" value="Some string value"/>


this I have to use in first JSP or then next JSP page??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Think about it for a minute. It acts just like any other form field.
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576



I have tried to use Hidden Fields values outside of form bean and checked the request parameters in the next JSP page ,but I cant fins that variable,

Is the right way of using ??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Hidden fields are still associated with a form--that's how they get submitted.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
As mentioned, hidden fields are associated with the form. So, put your hidden fields declaration within your form tag. You currently have it outside the form tag.

jacob deiter wrote:


I have tried to use Hidden Fields values outside of form bean and checked the request parameters in the next JSP page ,but I cant fins that variable,

Is the right way of using ??


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to add data in request object and pass it to next page?
 
Similar Threads
storing request object in session
passing parameter from jsp to servlet
Difference between <jsp:forward> and RequestDispatcher
use of response Object
how to select a static row at runtime in jsp?