Struts 2 action method and struts.convention.result.path not working

别来无恙 提交于 2019-12-08 03:09:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!