You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by maven apache <ap...@gmail.com> on 2010/12/29 08:13:36 UTC

How to save the valuestack when using the redirectaction result type

Hi:
In my application I first use the chain result type for one
action:"loginSub".

If login success,user should be taken to the manager page.
This is the core content in struts.xml:

    <package name="default" extends="struts-default" namespace="/">
        .....
        <action name="loginSub" class="com.test.action.LoginAction">
            <result name="success" type="chain">
                <param name="actionName">manager</param>
                <param name="namespace">/secure</param>
            </result>
            <result name="input">/jsp/login.jsp</result>
            <result name="error">/jsp/login.jsp</result>
        </action>
    </package>

    <package name="sec" extends="struts-default" namespace="/secure">
        <action name="manager">
            <result>/jsp/secure/manager.jsp</result>
            <result name="input" type="chain">
                <param name="actionName">loginPage</param>
                <param name="namespace">/</param>
            </result>
        </action>
    </package>

It works,when user login,the page will show the content in the
/jsp/secure/manager.jsp.

However the value in the browser address bar is also something like:

http://localhost:8080/Test/loginSub.action.

So once user refresh this page,it will result in a relogin.

After read the struts2 tutorial,I found the result type of
"redirectAction",it will change the value of the Browser address bar.
I change the "loginSub" action:

        <action name="loginSub" class="com.test.action.LoginAction">
            <..... the authentication interceptor>...
            <result name="success" type="redirectAction">
                <param name="actionName">manager</param>
                <param name="namespace">/secure</param>
            </result>
            <result name="input">/jsp/login.jsp</result>
            <result name="error">/jsp/login.jsp</result>
        </action>

Now after login,the browser address bar will change to :

*http://localhost:8080/Test/secure/manager.action*

Now no matter how frequently user refresh the page,it will not cause a
relogin.

However I found that I can not get some properties in the LoginAction.

I have a struts tag in the manager.jsp:

*<s:property value="userBean.username">*

Now using the redirectAction result type,I have no idea to get this value.

Any ideas?

BWT:
1)what's the difference between "Dispatcher Result","Redirect
Result","Redirect Action Result" and "Chain Result"?
I read the contents at "....struts.apache.org/2.2.1/docs/result-types.html",but
I am not exactly sure its meaning.

2)My action "manager" is a authentication required action,so I add a
authentication interceptor for them.

But how about user enter the url directly like this:
*
http://localhost:8080/Test/jsp/secure/manager.jsp?*

If so ,I do not think the interceptor will work.

How do you guys slove this problem?

Re: How to save the valuestack when using the redirectaction result type

Posted by Amol Ghotankar <gh...@gmail.com>.
Hello,

As Dave suggested one of your problem will be solved by keeping jsp's in
web-inf.


On Wed, Dec 29, 2010 at 6:19 PM, Dave Newton <da...@gmail.com> wrote:

> JSP pages should be under WEB-INF to avoid direct access; this has been a
> best practice for years.
>
> Dave
>  On Dec 29, 2010 1:14 AM, "maven apache" <ap...@gmail.com> wrote:
> > Hi:
> > In my application I first use the chain result type for one
> > action:"loginSub".
> >
> > If login success,user should be taken to the manager page.
> > This is the core content in struts.xml:
> >
> > <package name="default" extends="struts-default" namespace="/">
> > .....
> > <action name="loginSub" class="com.test.action.LoginAction">
> > <result name="success" type="chain">
> > <param name="actionName">manager</param>
> > <param name="namespace">/secure</param>
> > </result>
> > <result name="input">/jsp/login.jsp</result>
> > <result name="error">/jsp/login.jsp</result>
> > </action>
> > </package>
> >
> > <package name="sec" extends="struts-default" namespace="/secure">
> > <action name="manager">
> > <result>/jsp/secure/manager.jsp</result>
> > <result name="input" type="chain">
> > <param name="actionName">loginPage</param>
> > <param name="namespace">/</param>
> > </result>
> > </action>
> > </package>
> >
> > It works,when user login,the page will show the content in the
> > /jsp/secure/manager.jsp.
> >
> > However the value in the browser address bar is also something like:
> >
> > http://localhost:8080/Test/loginSub.action.
> >
> > So once user refresh this page,it will result in a relogin.
> >
> > After read the struts2 tutorial,I found the result type of
> > "redirectAction",it will change the value of the Browser address bar.
> > I change the "loginSub" action:
> >
> > <action name="loginSub" class="com.test.action.LoginAction">
> > <..... the authentication interceptor>...
> > <result name="success" type="redirectAction">
> > <param name="actionName">manager</param>
> > <param name="namespace">/secure</param>
> > </result>
> > <result name="input">/jsp/login.jsp</result>
> > <result name="error">/jsp/login.jsp</result>
> > </action>
> >
> > Now after login,the browser address bar will change to :
> >
> > *http://localhost:8080/Test/secure/manager.action*
> >
> > Now no matter how frequently user refresh the page,it will not cause a
> > relogin.
> >
> > However I found that I can not get some properties in the LoginAction.
> >
> > I have a struts tag in the manager.jsp:
> >
> > *<s:property value="userBean.username">*
> >
> > Now using the redirectAction result type,I have no idea to get this
> value.
> >
> > Any ideas?
>
You will have to push the bean on value stack again, if you want it to be
made available in redirected action and also set for which variable in the
parameter.

***This is a guess a issue with struts 2 that via such mechanism only int,
string etc basic values can be accessed but the complex objects can not be
accessed,

Even I am looking for better solution.



> >
> > BWT:
> > 1)what's the difference between "Dispatcher Result","Redirect
> > Result","Redirect Action Result" and "Chain Result"?
> > I read the contents at "....
> struts.apache.org/2.2.1/docs/result-types.html
> ",but
> > I am not exactly sure its meaning.
> >
> > 2)My action "manager" is a authentication required action,so I add a
> > authentication interceptor for them.
> >
> > But how about user enter the url directly like this:
> > *
> > http://localhost:8080/Test/jsp/secure/manager.jsp?*
> >
> > If so ,I do not think the interceptor will work.
> >
> > How do you guys slove this problem?
>



-- 


With Best Regards,

Amol Ghotankar
Cursive Technologies Pvt. Ltd.
www.cursivetech.com

Re: How to save the valuestack when using the redirectaction result type

Posted by Dave Newton <da...@gmail.com>.
JSP pages should be under WEB-INF to avoid direct access; this has been a
best practice for years.

Dave
 On Dec 29, 2010 1:14 AM, "maven apache" <ap...@gmail.com> wrote:
> Hi:
> In my application I first use the chain result type for one
> action:"loginSub".
>
> If login success,user should be taken to the manager page.
> This is the core content in struts.xml:
>
> <package name="default" extends="struts-default" namespace="/">
> .....
> <action name="loginSub" class="com.test.action.LoginAction">
> <result name="success" type="chain">
> <param name="actionName">manager</param>
> <param name="namespace">/secure</param>
> </result>
> <result name="input">/jsp/login.jsp</result>
> <result name="error">/jsp/login.jsp</result>
> </action>
> </package>
>
> <package name="sec" extends="struts-default" namespace="/secure">
> <action name="manager">
> <result>/jsp/secure/manager.jsp</result>
> <result name="input" type="chain">
> <param name="actionName">loginPage</param>
> <param name="namespace">/</param>
> </result>
> </action>
> </package>
>
> It works,when user login,the page will show the content in the
> /jsp/secure/manager.jsp.
>
> However the value in the browser address bar is also something like:
>
> http://localhost:8080/Test/loginSub.action.
>
> So once user refresh this page,it will result in a relogin.
>
> After read the struts2 tutorial,I found the result type of
> "redirectAction",it will change the value of the Browser address bar.
> I change the "loginSub" action:
>
> <action name="loginSub" class="com.test.action.LoginAction">
> <..... the authentication interceptor>...
> <result name="success" type="redirectAction">
> <param name="actionName">manager</param>
> <param name="namespace">/secure</param>
> </result>
> <result name="input">/jsp/login.jsp</result>
> <result name="error">/jsp/login.jsp</result>
> </action>
>
> Now after login,the browser address bar will change to :
>
> *http://localhost:8080/Test/secure/manager.action*
>
> Now no matter how frequently user refresh the page,it will not cause a
> relogin.
>
> However I found that I can not get some properties in the LoginAction.
>
> I have a struts tag in the manager.jsp:
>
> *<s:property value="userBean.username">*
>
> Now using the redirectAction result type,I have no idea to get this value.
>
> Any ideas?
>
> BWT:
> 1)what's the difference between "Dispatcher Result","Redirect
> Result","Redirect Action Result" and "Chain Result"?
> I read the contents at "....struts.apache.org/2.2.1/docs/result-types.html
",but
> I am not exactly sure its meaning.
>
> 2)My action "manager" is a authentication required action,so I add a
> authentication interceptor for them.
>
> But how about user enter the url directly like this:
> *
> http://localhost:8080/Test/jsp/secure/manager.jsp?*
>
> If so ,I do not think the interceptor will work.
>
> How do you guys slove this problem?