Question

I have problem with Struts2 action method and struts.convention.result.path Here is my struts.xml

<struts>
    <constant name="struts.action.extension" value="" />
    <constant name="struts.action.excludePattern" value="/.*\.(html|jsp),/static/.*"/>
    <constant name="struts.convention.result.path" value="/WEB-INF/pages/" />
    <package name="user" namespace="/user" extends="struts-default">
        <action name="login" class="loginAction" method="login">
            <result name="success">login.jsp</result>
        </action>
    </package>
<struts>

When I run url "localhost:8080/venus/user/login". It display error "HTTP Status 404 - /venus/user/login.jsp"

If I change login() method to execute() method, it works. Or if I change to <result name="success">/WEB-INF/pages/login.jsp</result>, it works.

Can anyone explain and teach me how use action method with result path config in xml? Thank you very much!

Was it helpful?

Solution

You should specify the absolute path name.

<result name="success">/login.jsp</result>

OTHER TIPS

When using Convention plugin, xml configuration isn't needed:

  • com.mycompany.actions.user -> namespaces "user"
  • LoginAction -> login.action
  • LoginAction#execute -> success -> user/login.jsp
  • LoginAction#login -> success -> user/login(-login|-success).jsp
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top