You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hns <ha...@yahoo.com> on 2008/02/28 14:31:59 UTC

about current action name acsess

hi
how can i access current action name from struts.xml file
-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15736383.html
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


Re: about current action name acsess

Posted by hns <ha...@yahoo.com>.
Thanks to you
and also thanks to kedar for great logic
but i dont know why postLoginURL remains empty in my case
so i have choose way of session it works fine right now but i dont know
about future problems of it
i have done like this

 Inside interceptor i wrote
------------------------
  if (!isAuthenticated) {

String urlGoingTo = actionInvocation.getProxy().getNamespace()+"/"+
        	 actionInvocation.getProxy().getActionName()+".do";
        	 session.put( "actionurl", urlGoingTo);


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>
            <result name="redirect"
type="redirect">${session.actionurl}</result>
            <interceptor-ref name="guest"/>
        </action>
-------------------

Login.java

-------------
if(session.get("actionurl") != null && !session.get("actionurl").equals(""))
        	 {
        		 return "redirect";
        	 }
                  
        	 return SUCCESS;
--------

Thanks
-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15773049.html
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


RE: about current action name acsess

Posted by hns <ha...@yahoo.com>.
Great !
you have  realize me abt difference between session and request
but i do not understand why this logic do not works  to me 
if u have little beat time to investigate my work i would like to attach my
core files
like 
login.java
login.jsp
my interceptor
my struts.xml  files

-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15798206.html
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


RE: about current action name acsess

Posted by hns <ha...@yahoo.com>.
it works now 
i made just this change in struts.xml
first i wrote

<global-results>
<result name="login" type="redirect-action">Login_input</result>
</global-results>

now it works fine when i  write

<global-results>
      <result name="login" type="chain">
          Login_input
          ${postLoginURL}
        </result>
    </global-results> 

something i could understand is because of result type chain inspite of
redirect action
is is  true?
-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15798429.html
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


RE: about current action name acsess

Posted by Kedar Choudhary <ke...@helixtechsolutions.com>.
Well, I'm not sure why the %{#postLoginURL} did not work for you.
Glad that you got it working using session as storage.
The issues in using session as storage for postLoginURL are pretty minor in
nature:

1) un-authenticated user tries to access privileged URL, say
/privileged.action, he is sent to login screen, but he navigates out to some
other page and then from elsewhere in the site clicks on "Login" link. In
such case, after successful login he should be taken to home page as he has
initiated the login. But using session to store postLoginURL, user will be
sent to the /privileged.action.
 
2) user has two browser windows open, in window-1 he tries to access
/privileged-1.action is taken to login page, he does not immediately
complete the login. In window-2, he tries to access /privileged-2.action is
taken to login page, does not complete the login here. He returns to
window-1 and completes the login. He returns to window-1 and completes the
login. Here he should be taken to /privileged-1.action but actually will be
taken to /previlged-2.action

3) user tries to access /previlged.action, is taken to login page, but user
goes for lunch break, completes the login after lunch break. He is taken to
home page as his session is gone by the time he completes the login.

In fact, there is one issue with the solution I was using.
It would not take user to postLoginURL if user makes a mistake in first
login attempt but succeeds second time. Following changes to the solution
given earlier will correct this issue:

=================
struts.xml
    <global-results>
      <result name="login" type="chain">
	  <param name="actionName">login_input</param>
	  <param name="postLoginURL">${postLoginURL}</param>
	</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>
============

Regards,
Kedar

-----Original Message-----
From: hns [mailto:hardik_982@yahoo.com] 
Sent: Saturday, March 01, 2008 12:01 PM
To: user@struts.apache.org
Subject: Re: about current action name acsess


After Inspecting postLoginURL I have found that entry of ctx hashtable
PostLoginURL remains in it but it can not come at Login.java(getter and
setter of PostLoginURL)
so i think some thing missing in it or wrong at login.jsp so value can not
come after submitting form at login.java 
-- 
View this message in context:
http://www.nabble.com/about-current-action-name-acsess-tp15736383p15773060.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


Re: about current action name acsess

Posted by hns <ha...@yahoo.com>.
After Inspecting postLoginURL I have found that entry of ctx hashtable
PostLoginURL remains in it but it can not come at Login.java(getter and
setter of PostLoginURL)
so i think some thing missing in it or wrong at login.jsp so value can not
come after submitting form at login.java 
-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15773060.html
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


Re: about current action name acsess

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
hns wrote:
> please help 
> i am waiting for your reply
>   
Kedar's example looks really good.  Double-check that you've done 
everything he's asked
Put a breakpoint inside your interceptor to see if postLoginURL is being 
built correctly.
Assist your debugging by forcing it to return redirect every time.

I would have thought the hidden field should have been this though:

<s:hidden name="postLoginURL" value="%{postLoginURL}"></s:hidden>

(I have removed the # as # implies a root object rather than a property of the action)


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


RE: about current action name acsess

Posted by hns <ha...@yahoo.com>.
please help 
i am waiting for your reply
-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15756791.html
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


RE: about current action name acsess

Posted by hns <ha...@yahoo.com>.
Thanks 

yes i have put hidden field already as per you told 
but it can not show any param of requestURL in url
i think i can not get any value of %{#postLoginURL}
what actually happens i dont know
how can i check value of postLoginURL is available upto login.jsp
or not
can i use 
<%=ActionContext.getContext().getParameters()) %>
but it shows null at login.jsp

Regards 
Hardik shah
-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15755941.html
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


RE: about current action name acsess

Posted by Kedar Choudhary <ke...@helixtechsolutions.com>.
Have you put
    <s:hidden name="postLoginURL" value="%{#postLoginURL}"></s:hidden>
in login form?
Check the source of rendered login page to see if this hidden input is
properly set to the URL we want to redirect.

Regards,
Kedar

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


Thanks 
i have put setter and getter for postLoginURL
but using eclipse debugger i have found that postLoginURL is remains empty
i dont know why
so my result becomes success  instead of redirect 
what is an issue?
please help me?
-- 
View this message in context:
http://www.nabble.com/about-current-action-name-acsess-tp15736383p15755153.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


RE: about current action name acsess

Posted by hns <ha...@yahoo.com>.
Thanks 
i have put setter and getter for postLoginURL
but using eclipse debugger i have found that postLoginURL is remains empty
i dont know why
so my result becomes success  instead of redirect 
what is an issue?
please help me?
-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15755153.html
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


RE: about current action name acsess

Posted by Kedar Choudhary <ke...@helixtechsolutions.com>.
postLoginURL is coming from form post of login form(login.jsp).

LoginAction.java
	private String postLoginURL;
	//getter/setter

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


Nice guidance!
i want to ask just one thing how do i get  

if(postLoginURL != null && !postLoginURL.isEmpty())
          return "redirect"; 

it means i have to set 
if(ActionContext.getContext().get("postLoginURL") != null &&
ActionContext.getContext().get("postLoginURL").isEmpty())

or another thing
 i am not experienced programmer in struts please help me!
-- 
View this message in context:
http://www.nabble.com/about-current-action-name-acsess-tp15736383p15754224.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


RE: about current action name acsess

Posted by hns <ha...@yahoo.com>.
Nice guidance!
i want to ask just one thing how do i get  

if(postLoginURL != null && !postLoginURL.isEmpty())
          return "redirect"; 

it means i have to set 
if(ActionContext.getContext().get("postLoginURL") != null &&
ActionContext.getContext().get("postLoginURL").isEmpty())

or another thing
 i am not experienced programmer in struts please help me!
-- 
View this message in context: http://www.nabble.com/about-current-action-name-acsess-tp15736383p15754224.html
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


RE: about current action name acsess

Posted by Kedar Choudhary <ke...@helixtechsolutions.com>.
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


Re: about current action name acsess

Posted by hns <ha...@yahoo.com>.
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.html
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


Re: about current action name acsess

Posted by Laurie Harper <la...@holoweb.net>.
hns wrote:
> hi
> how can i access current action name from struts.xml file

How would you define 'current action' in the context of a configuration 
file? Can you explain what you're trying to achieve?

L.


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