在編寫背景登陸子產品時,将許多預設的設定放在一個名為default的package
裡。然後再定義其他package繼承該包。之前我的struts.xml配置如下
<struts>
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactor y" />
<constant name="struts.devMode" value="true" />
<package name="exam_default" extends="struts-default" namespace="/">
<!--自定義攔截器及攔截器棧-->
<interceptors>
<!--使用者認證攔截器-->
<interceptor name="authentication" class="action.admin.AuthenticationIntercepto r"/>
<!--使用者認證攔截器棧,用于防止使用者非法通路-->
<interceptor-stack name="user" >
<interceptor-ref name="authentication" />
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
<interceptor-stack name="guest" >
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<!--全局異常映射-->
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception"/>
</global-exception-mappings>
<!--全局result-->
<global-results>
<result name="error">/error.jsp</result>
</global-results>
</package>
<package name="admin" extends="exam_default" namespace="/admin">
<action name="login" class="login">
<result type="redirectAction">index</result>
</action>
<action name="index">
<result>index.jsp</result>
</action>
</package>
</struts>
各位,誰看出來這哪裡錯了嗎??反正最開始我是沒看出來。一運作程
序來個錯誤。
“The content of element type "package" must match "(result-types?,interceptors?,default-interceptor-ref?,default-action-ref?,default-class-ref?,global-results?,global-exception-mappings?,action*)". ”
剛看到這個錯誤我就想,哪個也沒寫錯呀。仔細對了好幾遍也沒發現哪個屬
性寫錯了。最後Google了一下,看了别人寫的文章豁然開朗了。
這個錯誤的意思是,package裡元素必須按照一定的順序排列。這個順序
就是
result-types
interceptors
default-interceptor-ref
default-action-ref
default-class-ref
global-results
global-exception-mappings
action*(就是所有的action放到最後)