tags:

views:

40

answers:

2

I'm trying to redirect to the page where the user tried to login.

I mean, somepage → login → somepage

I know this;

In LoginAction

HttpServletRequest request = ServletActionContext.getRequest();
String url = request.getServletPath();
setUrl(url);

In struts.xml

 <action name="LoginPro" method="login" class="LoginAction">
    <result type="redirect">${url}</result>
    <result name="input" type="tiles">login.error</result>
 </action>

But it's not working. The requested url is always "LoginPro" which is handling login process. When a user clicks login button, page goes to LoginPro. So the request url is always loginPro...

It seems to be this way; somepage → login → loginPro → LoginAction(request url is loginPro..) → loginPro

How can I redirect users to the page where they tried to login?

A: 

How are you redirecting to your login action? If it's only a single place (or some common base that does the redirection) could you add a variable to the session, make your Login action SessionAware, and then just retrieve/remove the source URL after a successful login, and use that?

Shawn D.
My login form is always in the left part of the page.(included by tiles). And.. sorry I don't get what you mean. I don't know how to find URL in session..?
Deckard
What I mean is, let's say you wanted to access some location that required a login. Do you say "You need to login here" and provide a link, or do you return a 'login' result and redirect to the Login action?
Shawn D.
+1  A: 

Thanks for your answers.

I found this way and it works!

url = request.getHeader("referer");

This url is the exact url where the action is called.

Deckard