• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.setAttribute not working while forwarding

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Manjunath Subramanian
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Absolute" of course meaning from the web app root, not the server's...
 
vicky vickyqwe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic