原本全都正确的逻辑。添加interceptor后显示如下错误。
Caused by: 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*)".
原因是struts的dtd定义中对package定义为:package (result-types?,interceptors?,default-interceptor-ref?,default-action-ref?,default-class-ref?,global-results?,global-exception-mappings?,action*)
这里表示package种的元素出现是有先后顺序的,要么不添加,要么就按照顺序。
把interceptor位置换一下。
1 <package name="front" namespace="/front" extends="struts-default"> 2 <result-types> 3 <result-type name="tiles" 4 class="org.apache.struts2.views.tiles.TilesResult" /> 5 </result-types> 6 7 <interceptors> 8 <interceptor name="login" class="loginInterceptor" /> 9 <interceptor name="adminInfoInterceptor" class="adminInfoInterceptor" /> 10 <interceptor-stack name="loginStack"> 11 <interceptor-ref name="login" /> 12 <interceptor-ref name="adminInfoInterceptor"/> 13 <interceptor-ref name="defaultStack" /> 14 </interceptor-stack> 15 </interceptors> 16 17 <global-results> 18 <result name="pageNotFind">/front/pageNotFind.jsp</result> 19 <result name="webNotFind">/front/pageNotFind.jsp</result> 20 </global-results> 21 22 <!-- 网站首页 --> 23 <action name="goWebIndex" class="goWebIndexAction"> 24 <result name="success" type="tiles">${web.pageTemplate.dir}/index.tiles</result> 25 </action> 26 27 </package>