Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

req.setAttribute problem

 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a very interesting problem. Let me post some code first and then I will explain.


Here is the problem. In the jsp page, reqest.getAttribute( "invalidLogin" ) is always null. I know the logic is going through that path because the url is set properly and the log is being hit. Does anyone have any ideas on this?
 
Andreas Amstutz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is the problem. In the jsp page, reqest.getAttribute( "invalidLogin" ) is always null. I know the logic is going through that path because the url is set properly and the log is being hit. Does anyone have any ideas on this?

You can get arround this by using the RequestDispatchers forward() method.
That way the current request object is forwarded and the requierd attribute is accessible on the forwarded page.

Andreas
 
Pritam Banerjee
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because the forward(req, res) method of RequestDispatcher takes the request and the response of the current HTTP request to the JSP. It is like forwarding the same Http request.
On the other hand, sendRedirect(urlStr) actually sends a completely new Http request to the server (to the new URL, the JSP in this case) and it abandons all parameters in the current HttpServletRequest object.
So, no wonder, you get the null value for the parameter in the JSP.
There is no way you can pass the current request parameters to the redirected URL, unless you put them in the session. But that's a lil clumsy way to do it ;-)
Pritam
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. I am really learning a lot on this project and from all of you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic