问题
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!
回答1:
You should specify the absolute path name.
<result name="success">/login.jsp</result>
回答2:
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
来源:https://stackoverflow.com/questions/18880572/struts-2-action-method-and-struts-convention-result-path-not-working