struts.xml配置如下
<package name="news" extends="json-default" namespace="/news">
<interceptors>
<interceptor name="adminLogin" class="com.zzy.interceptor.AdminInterceptor"></interceptor>
<interceptor-stack name="loginStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="adminLogin"/>
</interceptor-stack>
</interceptors>
<action name="*" class="com.zzy.action.NewsAction" method="{1}">
<result name="go_addN">/WEB-INF/NewsPage/addNews.jsp</result>
<result name="go_listN">/WEB-INF/NewsPage/listNews.jsp</result>
<result name="addnews" type="json"> <!-- 添加 -->
<param name="root">message</param>
</result>
<result name="pageJson" type="json"> <!-- 获取分页 -->
<param name="root">pageJson</param>
</result>
<result name="go_update">/WEB-INF/NewsPage/updateNews.jsp</result> <!-- 更新跳转 -->
<result type="json" name="update_success"> <!-- 更新新闻 -->
<param name="root">message</param>
</result>
<result type="json" name="delNews"> <!-- 删除新闻 -->
<param name="root">status</param>
</result>
<!-- 对应方法 -->
<interceptor-ref name="adminLogin"/>
<interceptor-ref name="defaultStack"/>
<allowed-methods>addNews,listNews,goUpdate,updateNews,delNews,go_addN,go_listN</allowed-methods>
</action>
</package>
<package name="category" extends="json-default" namespace="/category">
<action name="*" class="com.zzy.action.NewsAction" method="{1}">
<result name="go_addC">/WEB-INF/CategoryPage/addCategory.jsp</result>
<result name="go_listC">/WEB-INF/CategoryPage/listCategory.jsp</result>
<result name="addCategory" type="json"><!-- 添加类型 -->
<param name="root">message</param>
</result>
<result name="listCategory" type="json"><!-- 获取所有 -->
<param name="root">pageJson</param>
</result>
<result name="go_update">/WEB-INF/CategoryPage/updateCategory.jsp</result><!-- 更新跳转 -->
<result type="json" name="update_success"><!-- 更新操作 -->
<param name="root">message</param>
</result>
<result type="json" name="delCategory"><!-- 删除分类 -->
<param name="root">status</param>
</result>
<interceptor-ref name="adminLogin"/>
<interceptor-ref name="defaultStack"/>//*******报错提示代码行*******
<allowed-methods>addCategory,listCategory,goUpdateC,updateCategory,delCategory,go_addC,go_listC</allowed-methods>
</action>
</package>
最后发现是因为:
name="defaultStack"
的拦截器只在<package name="news"
包里面定义,<package name="category"
包没有.
解决方法:
将拦截器独立放在一个package
里,其他action的package
继承这个包