struts命名空間的遇到的問題解決

表單中請求action:bookquert java

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

struts.xml部份內容: jsp

<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>
post

此時執行包含上述表單的代碼,產生以下異常: this

HTTP Status 500 -

type Exception report spa

message code

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

exception server

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. xml

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>

相關文章
相關標籤/搜索