1
votes

You will suppose this is a big question.but there might be a simple problem which I can't find the reason.

There is a form( a simple login) whose action name is 'loginAction' in a jsp page called 'index.jsp' . In the action class, the execute() method checks whether the username,password are valid. If it is a valid login, execute() method returns SUCCESS which forward to another jsp page called 'account.jsp' in a folder called 'jsp' inside WEB-INF.

The problem is that, struts.xml forwards all valid logins to the relavant url , but the page(account.jsp) cannot be retrieved.Browser gives 404 error.But the url which the browser says 'not available' was just copied and pasted to the browser's address bar manually. Then the page is displayed !!!
Here is the struts.xml file

<struts>

<include file="/struts_auth.xml" />
<package name="default" extends="struts-default" >

    <action name="login" >
        <result>index.jsp</result>
    </action>        
    <action name="loginAction" class="com.app.action.LoginAction">
        <result name="success">/auth/acc</result>    
        <result name="input">index.jsp</result>
    </action>

</package>

Here is the struts_auth.xml file which is included in above struts.xml

<struts>

<package name="author" extends="default" namespace="/auth" >

    <action name="acc">
        <result name="success">/WEB-INF/jsp/account.jsp</result>  
        <result name="input">index.jsp</result>
    </action>   

</package>

and this is what browser says as the reason
description: The requested resource (/app/auth/acc) is not available. But if this url (http://localhost:8084/app/auth/acc)just copied into the browser's address bar, it just shows the real page . Please let me know where my problem is.

2
I dont think /WEB-INF part is required in your success result.Have you tried without that part? - Anupam
Thanks Mr. anu for your attention. I put that jsp because of some security purpose. any way, I tried putting that account page inside the web folder where other pages normally exists.<action name="acc"> <result name="success">/account.jsp</result> <result name="input">index.jsp</result> </action> But it also didn't work. - Débora

2 Answers

3
votes

For better understanding refer the following link. How to redirect to another action

  <!-- Redirect to another namespace -->
    <result name="success" type="redirectAction">
        <param name="actionName">acc</param>
        <param name="namespace">/auth</param>
    </result>
1
votes

problem lies here:<result name="success">/auth/acc</result>. If there is no type name given in the node,then struts2 itself will set dispatcher as the default type.You can modify your code like this: <result name="success" type="redirectAction"> <param name="actionName">actionName</param> <param name="namespace">namespace</param> `