This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes req.setAttribute problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "req.setAttribute problem" Watch "req.setAttribute problem" New topic
Author

req.setAttribute problem

Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
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?


Matthew Phillips
Andreas Amstutz
Greenhorn

Joined: May 16, 2002
Posts: 2

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

Joined: May 08, 2002
Posts: 9
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

Joined: Mar 09, 2001
Posts: 2676
Thanks for the info. I am really learning a lot on this project and from all of you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: req.setAttribute problem
 
Similar Threads
Validate() method of ActionForm
Bilingual JSP application
I M NOT ABLE TO DEFINE VARIABLES IN JSP.
Has anyone seen this error before??
RequestDispatcher.forward problem