struts命名空间的遇到的问题解决

表单中请求action:bookquert

<s:form action="bookquery" method="post">...</s:form>

struts.xml部分内容:

<package name="default" extends="struts-default" namespace="/">
         <action name="bookquery" class="com.leung.action.BookQueryAction">
            <result name="input">/page/notfound.jsp</result>
            <result name="success">/page/found.jsp</result>
            <result name="error">/page/query.jsp</result>
        </action>
    </package>

此时执行包含上述表单的代码,产生如下异常:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
	org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
	org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
	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:501)
	org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.

Apache Tomcat/7.0.27


原因是:表单中请求的action为bookquery,其中命名空间为空,而在struts-xml文件中没有声明默认命名空间(空命名空间)时的情况,故因为找不到该action而抛出异常。

修改:给表单中请求的action:bookquery指定struts-xml中某个已声明的命名空间,或者struts.xml中声明默认命名空间。

如:

<s:form action="/bookquery" method="post">...</s:form> 或

<s:form action="bookquery" method="post" namespace="/">...</s:form>

或者

struts.xml部分内容:

<package name="default" extends="struts-default">
         <action name="bookquery" class="com.leung.action.BookQueryAction">
            <result name="input">/page/notfound.jsp</result>
            <result name="success">/page/found.jsp</result>
            <result name="error">/page/query.jsp</result>
        </action>
    </package>

你可能感兴趣的:(命名空间注意事项)