Struts2想在global Package里拦截404请求,求配置代码,如果可能,最好跳转至一个ACTION里来处理事件

讨厌web.xml配置,然后同求java.lang.NoSuchMethodException(Struts2)拦截处理跳转的方式,高分哦!!!... 讨厌web.xml配置,然后同求java.lang.NoSuchMethodException(Struts2)拦截处理跳转的方式,高分哦!!! 展开
 我来答
eddie_zou
2013-12-23 · 超过18用户采纳过TA的回答
知道答主
回答量:45
采纳率:100%
帮助的人:28.3万
展开全部
如果讨厌在web.xml配置的话,那只能在struts.xml里只能对(错误类型)进行拦截。
例如:
<!-- 全局异常 -->
<global-exception-mappings>
<exception-mapping result="nullExce" exception="java.lang.NullPointerException"></exception-mapping>
</global-exception-mappings>
<!--全局异常跳转-->
<global-results>
<result name="nullExce">/500page.jsp</result>
</global-results>

<!-- action里异常跳转 -->
<action name="AAA_*" class="com.test.aaa" method="{1}">
<result name="nullExce">AAA_index</result>
</action>

web.xml里加入错误页面代码配置,就可以实现你需要的拦截404(错误代码)。
例:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<error-page>
<error-code>500</error-code>
<location>/500page.jsp</location>
</error-page>

<error-page>
<error-code>404</error-code>
<location>/404page.jsp</location>
</error-page>
百度网友dfd5459
2013-12-23 · TA获得超过365个赞
知道小有建树答主
回答量:358
采纳率:0%
帮助的人:284万
展开全部
<global-exception-mappings>
<exception-mapping result="exception" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
<global-results>

<result name="exception" type="redirect">/page/error.html</result>
</global-results>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ximengsiguo
2013-12-23 · 超过21用户采纳过TA的回答
知道答主
回答量:123
采纳率:0%
帮助的人:60.4万
展开全部
<default-action-ref name="resourceNotExisted" />
<action name="resourceNotExisted">
<result>/WEB-INF/404.jsp</result>
</action>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式