转 struts2自定义404页面以及返回status code为404的方法
文章目录
问题描述
1.访问不存在的资源文件(.html.txt等)返回tomcat的404页面
2.访问不存在的action返回struts2的错误页面
3.访问不存在的action返回的status code为200
解决方法
1.在web.xml中指定错误页面
<error-page>
<error-code>404</error-code>
<location>/404error.jsp</location>
</error-page>
2.struts.xml中指定全局错误页面
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
3.制定错误页面返回的status code = 404
<global-results>
<result name="error" type="httpheader">
<param name="error">404</param>
</result>
</global-results>
问题解释
1.根据同样的方法,还可以制定50x的错误页面
2.对于全局的exception,返回到error
3.指定error的处理方法,注意 type="httpheader"

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论