aspose file tools*
The moose likes Servlets and the fly likes using request.sendRedirect?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "using request.sendRedirect??" Watch "using request.sendRedirect??" New topic
Author

using request.sendRedirect??

Joe Schaffer
Greenhorn

Joined: Mar 24, 2004
Posts: 29
Hi everybody,
I have the following Problem:
When a user wants to access the userpage he has to perform a login first. I have done this with a LoginHandler. There the user enters his username and depending on a known username he will be forwarded with the command request.sendRedirect("URL");
My Problem is, I also need the username and maybe even some other data forwarded to the servlet. What I do not want to do is to forward it with
?user=name&...
If I perform request.getParameter("name"); after I redirected the page the data I had in there is gone.
Is there another command how to call this new URL and send the data similar to a function call? functioncall("URL",name,data...);
Thanks for your help
Joe
Satya Komirisetti
Greenhorn

Joined: Apr 23, 2004
Posts: 11
use Session or Servletcontext to persist data between the servlets.eg before redirecting add the username to session by
request.getSession().setAttribute("Username","value");
and retrieve it in destination URL by
String name = request.getSession().getAttribute("Username");
(note this is when Session is Active).


satya
danny liu
Ranch Hand

Joined: Jan 22, 2004
Posts: 185
using session is better than URL rewriting in this case.
dan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

Or don't do a redirect and instead forward the request to the page. The user credentials will then still be available.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Arnold Reuser
Ranch Hand

Joined: Nov 20, 2003
Posts: 194
Maybe another way of thinking : use declarative security instead and let the webserver handle your security problems.
In such a situation you don't need sendRedirect at all.
When you don't like this way of thinking : indeed, use forward and your request-parameters will still be available.
[ May 01, 2004: Message edited by: Arnold Reuser ]
 
Don't get me started about those stupid light bulbs.
 
subject: using request.sendRedirect??