wood burning stoves*
The moose likes Servlets and the fly likes Issue with request.setAttribute(String,obj) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Issue with request.setAttribute(String,obj)" Watch "Issue with request.setAttribute(String,obj)" New topic
Author

Issue with request.setAttribute(String,obj)

Ren Sha
Greenhorn

Joined: Mar 08, 2012
Posts: 9
Hi,

I have 2 servlet pages and 1HTML page


HTML: Biodata form, using POST method
Servlet1:POST method , redirecting to Servlet2
Servlet2:need to access some values from the Biodata form


I'm using request.setAttribute(Str,obj) on Servlet1 and request.getAttribute() on Servlet2. I dont want to use RequestDispatcher or session.
What i understand is i can access the values(Str) if i'm using it only in consecutive page.
But I'm getting "null" as result.

Can anyone please help me in this
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

When you redirect, a new request is made and so any scoped variables placed on the original request are lost. Either use the session, or place the values on the URL as request parameters.

And before you say "I don't want to use the session" again, what's the valid reason for that?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ren Sha
Greenhorn

Joined: Mar 08, 2012
Posts: 9
I just want to pass this value only in one page, so i was wondering is there any way i can do it without using session or RequestDispatcher.

I'm new to Java and dont have much idea about it till now so just trying to understand it with doing some examples.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

As I said, if it's a text value you could also pass it as a request parameter on the URL.

Other possibilities include storing the data in a database to be retrieved on the next page.
Ren Sha
Greenhorn

Joined: Mar 08, 2012
Posts: 9
Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Issue with request.setAttribute(String,obj)
 
Similar Threads
pageContext vs request vs page
server to server call
Inter-Servlet Communication
Form Variables
Servlet - doGet - doPost - parameter