日期:2014-05-17  浏览次数:20740 次

Struts2命名空间的问题
struts.xml
XML code

<package name="struts2" extends="struts-default" namespace="/user">
        <action name="index" class="loginAction">
            <result name="input">/index.jsp</result>
            <result name="success">/result.jsp</result>
            <result name="fail">/index.jsp</result>
        </action>
    </package>


index.jsp
HTML code

<s:form action="user/index.action" method="post">
        <s:textfield name="username" label="username"></s:textfield>
        <s:password name="password" label="password"></s:password>
        <s:submit></s:submit>
    </s:form>



路径:http://localhost:8080/Struts2/index.jsp
当我第一次输入错误的用户名和密码的时候回自动返回到登录界面,这时连接地址为:
http://localhost:8080/Struts2/user/index.action
其中user为我定义的命名空间
这时候我再次用正确的用户名和密码登录的时候,会报如下错误
HTML code

Struts Problem Report
Struts has detected an unhandled exception: 

Messages: There is no Action mapped for namespace /user/user and action name index. 
 


--------------------------------------------

Stacktraces
There is no Action mapped for namespace /user/user and action name index. - [unknown location] 
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java: