This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes getAttribute after sendredirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getAttribute after sendredirect" Watch "getAttribute after sendredirect" New topic

getAttribute after sendredirect

Joe Schaffer

Joined: Mar 24, 2004
Posts: 29
Hi everybody,

I have servlet (LoginHandler) which I use for several servlets to check if special logins have already taken place. My forward procedure is always something like this:

My problem is, that I want to access the attribute from the new servlet Register. How is this possible? I know I can forward the Information as an parameter, but I would prefer attributes. Any ideas how to solve this?

Best regards

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60752

Because the redirect will result in the browser generating a new request, the one to which you are attaching the attribute goes out of scope as soon as the response is sent to the client.

You'll either need to use a parameter, or to attach the attribute to a higher-scoped context (session or application), whichever makes the most sense for your app.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60752

Another alternative is to use a forward rather than a redirect, which will not result in a new request. Whether that makes sense or not in your app, you'll need to determine.
I agree. Here's the link:
subject: getAttribute after sendredirect
Similar Threads
JSF Accessing Bean Data
using request.sendRedirect??
relation between backing beans
Trouble calling this method