struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kedar Choudhary" <ked...@helixtechsolutions.com>
Subject RE: about current action name acsess
Date Fri, 29 Feb 2008 07:29:34 GMT
When you are directing the user to login page, you need to 'remember' the
action (rather URL) he was invoking. This needs to be made available to
Login action so that on successful login user can be redirected to the page
he was originally trying to access.

One of the ways to remember the original URL is to store it in session. But
there are certain issues with this approach. I prefer passing around the
original URL to login form and then to Login action.

public class AuthenticationInterceptor implements Interceptor {
  public String intercept(final ActionInvocation actionInvocation)
      throws Exception {
......
    if (!isAuthenticated) {
      final ActionContext ctx = actionInvocation.getInvocationContext();
      final HttpServletRequest request = (HttpServletRequest) ctx
          .get(StrutsStatics.HTTP_REQUEST);
      if (request != null) {
        StringBuffer requestURL = request.getRequestURL();
        if (request.getQueryString() != null) {
          requestURL.append("?").append(request.getQueryString());
        }
        ctx.put("postLoginURL", requestURL.toString());
      }
      return Action.LOGIN;
    }
    ...
  }
}

struts.xml
    <global-results>
      <result name="login">login.jsp</result>
    </global-results>

login.jsp
  <s:form label="Login" action="login">
    <s:textfield key="loginId" />
    <s:password key="password" />
    <s:hidden name="postLoginURL" value="%{#postLoginURL}"></s:hidden>
    <s:submit />
  </s:form>

LoginAction.java
  public String execute() throws Exception {
  ...
      if(user != null) {
        if(postLoginURL != null && !postLoginURL.isEmpty())
          return "redirect";
        return SUCCESS;
      }
  ...
  }

struts.xml
    <action name="login_*" method="{1}" class="LoginAction">
      <result type="redirect-action">home</result>
      <result name="redirect" type="redirect">
        ${postLoginURL}
      </result>
    </action>

-----Original Message-----
From: hns [mailto:hardik_982@yahoo.com] 
Sent: Friday, February 29, 2008 11:29 AM
To: user@struts.apache.org
Subject: Re: about current action name acsess


i have one interceptor(reference of mailreader example of 2.0.11 ) for check
in session about username
because
if person click on some authorized link like portfolio they should directly
to login action 
i have achieved this thing using interceptor

now my problem is that
when person submit his username and password ,he directly goes to the
mainmenu action 
because i have set in struts.xml
---------------------------------
<action name="Login_*"  method="{1}" class="authentic.Login">
            <result name="input">/Login.jsp</result>
            <result name="cancel" type="redirect-action">Welcome</result>
            <result type="redirect-action">MainMenu</result>
            <interceptor-ref name="guest"/>
        </action>



<action name="portfol_main"  >
	<interceptor-ref name="user"/>
	<result>portfolmain.jsp</result>
	</action>
------------------------------------
but i want to grab them directly to portfol_main action 
how  can i achieve it?


-- 
View this message in context:
http://www.nabble.com/about-current-action-name-acsess-tp15736383p15752667.h
tml
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message