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 request.setAttribute not working while forwarding 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 "request.setAttribute not working while forwarding" Watch "request.setAttribute not working while forwarding" New topic
Author

request.setAttribute not working while forwarding

Vijay Kashyap
Ranch Hand

Joined: Jul 30, 2001
Posts: 74
Hi,
I am using the following code (in my servlet) for forwarding request to another page but whatever attributes being set before forwarding the request are getting lost. Could any body please point me out what I am doing wrong? Also whats the difference if I get Request dispatcher from HttpServletRequest rather than ServletContext ?

Regards,
Vijay
Vijay Kashyap
Ranch Hand

Joined: Jul 30, 2001
Posts: 74
I got it. I am using getParameter to retrieve values in JSP which is causing all the problem. But still do point out whats the differenece in getting RequestDispatcher from SevletContext / HttpServletRequest ?
Regards,
Vijay
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
Hello ,
I feel the data is getting lost because session is getting invalidated as the session id is not being passed by the first servlet to the next servlet.
u before u farward the url attach the session id to it . u can do it by calling encodeURL method of HttpServletResponse class


Try and Try Till u succeed<br /> <br />Sandeep Jain
Manjunath Subramanian
Ranch Hand

Joined: Jul 18, 2001
Posts: 236
Vijay:
getRequestDispatcher(String URL) in ServletContext - takes an absolute URL as an argument where as the method in HttpServletRequest takes an argument which can be either an absolute URL or
a relative URL
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
"Absolute" of course meaning from the web app root, not the server's...


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
vicky vickyqwe
Greenhorn

Joined: Feb 28, 2011
Posts: 2
Vijay Kashyap wrote:I got it. I am using getParameter to retrieve values in JSP which is causing all the problem. But still do point out whats the differenece in getting RequestDispatcher from SevletContext / HttpServletRequest ?
Regards,
Vijay

then what did you use to correct the problem???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

vicky vickyqwe wrote:then what did you use to correct the problem???

One question mark is sufficient.

The solution is to use the correct means on the JSP to reference the request-scoped variable. That means the EL (expression language).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: request.setAttribute not working while forwarding
 
Similar Threads
Forward to JSP outside of war
call servlet files from different war
request.getAttribute() returns null in jsp
jsp-vector
Servlet to servlet