This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes adding a new value to the request... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "adding a new value to the request..." Watch "adding a new value to the request..." New topic
Author

adding a new value to the request...

Bala Krishniah
Ranch Hand

Joined: Dec 14, 2000
Posts: 81
Hello,
I need to add a new value to the request object. I am using the
request.setAttribute(String,Object)
and then using request dispatcher to forward the request from a servlet to another servlet,
but the added attributes dont seem to forwarded,
how do forward an request object along with the newly added value?
Thanks
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
In general redirecting requests in this way does not pass the attributes. Why not put your values in the session, and retrieve them in the destination servlet?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Bala Krishniah
Ranch Hand

Joined: Dec 14, 2000
Posts: 81
The problem is the code to loginServlet is already created and we dont want to touch the code. In LoginServlet we are also creating a brand new session object. From DataServlet I am passing two values in the request which is already there. But I also need to add one more brand new one into the request, before I forward to the LoginServlet.
One thing I can to is call the DataServlet by passing all the three values in the request and directly forward this to the LoginServlet.
But I have to change all the links in many places. So I thout I could just add here before forwarding the request.
Is there a way?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Personally I strongly disagree with putting transient information on the Session object.
The first reason is that sessions are generally pretty heavy and you end up packing it with extra data that sits on the server if the session isn't invalidated or until the server cleans it up.
Secondly it can cause unexpected application behaviour if the client uses the back button or jumps several pages backwards.
Which app server are you using? It might be a bug in their implementation of setAttribute()
Bala Krishniah
Ranch Hand

Joined: Dec 14, 2000
Posts: 81
I am using VAJ with WebSphere....
I am doing,
request.setAttribute("action","LOGIN");
request.setAttribute("type","name");
RequestDispatcher reqDispatcher = this.getRequestDispatcher("webapp/LoginServlet");
reqDispatcher.forward(request, response);

But the attibutes action and type are not being passed.
What am I doing wrong?
 
 
subject: adding a new value to the request...
 
Similar Threads
response.setHeader not working
Calling another servlet from the current servlet?
problems adding new parameters to a request
Regarding requestdispatcher ??
Request Dispatch adding new parameters