This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Best way for forwarding request after login Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best way for forwarding request after login" Watch "Best way for forwarding request after login" New topic

Best way for forwarding request after login

Ashraf Fouad
Ranch Hand

Joined: Oct 07, 2001
Posts: 80
I'm sending emails from my application to the users of the application, these emails contain URLs to specific pages with different parameters, but my application requires login before anyone can view or make action.

So I will need to check if the user in session if not, forward to login page with the required parameters, then the login page submits to me after login as defined in the email.

What is the best solution for this situation, I'm using Struts 1.1 on SUNONE 7 application server, if provided code samples it will be great.


Ashraf Fouad
Shraga van Shufel
Ranch Hand

Joined: Apr 20, 2003
Posts: 33

If I understand correctly you would like the users to reach a certain URI (an action in your case), if the user can not be found in the session the user will be forwarded to the login page and after successful authentication will be send to the original desired action.

You can achieve it using the following:
* In your target action check if user exist in the session
* If not use the request methods (getRequestURI, getQueryString) to build a url and assign it to the session
* forward the user to the login action
* After the user got authenticated check if your session contained the url reference you submit in your actual action.
* If the reference exist then create a new Action forward and assign it the url, if not send it to the original page you sending the users after login.

Hope it helps
It is sorta covered in the JavaRanch Style Guide.
subject: Best way for forwarding request after login
Similar Threads
How to use j_security_check directly (skip the login page)?
Retrieve current Login ID
Weird Form Auth and javascript behavior
How to redirect to a page after user authentication
Login into JSP through JAVA