Struts2中自定义404错误页面
来源:互联网 发布:美国国立指南数据库 编辑:程序博客网 时间:2024/05/18 08:57
目的:
客户访问一个该网站下不存在的action,为了给客户一个友好的界面提示
在struts.xml中配置
<default-action-ref name="404Error"></default-action-ref><action name="404Error"><result type="redirect">/error/404error.html</result></action>
这样defalut-action-ref就是当用户输入非法的action时,所匹配的action,默认到ActionSupport中并返回Action.SUCCESS
但是在struts2中,如果用户输入的是非法的http://xxxxxxxx/xx.jsp时,在Struts2的FilterPreparedFilterAndExecuter中只会对
<span style="white-space:pre"></span>/xxx和/xxx.action进行拦截见(ActionMapping中的部分代码),所以<span style="font-family: Arial;">defalut-action-ref此时就不起作用了</span>
<pre name="code" class="java"> protected String dropExtension(String name, ActionMapping mapping) { if (extensions == null) { return name; } for (String ext : extensions) { if ("".equals(ext)) { // This should also handle cases such as /foo/bar-1.0/description. It is tricky to // distinquish /foo/bar-1.0 but perhaps adding a numeric check in the future could // work int index = name.lastIndexOf('.'); if (index == -1 || name.indexOf('/', index) >= 0) { return name; } } else { String extension = "." + ext; if (name.endsWith(extension)) { name = name.substring(0, name.length() - extension.length()); mapping.setExtension(ext); return name; } } } return null; }
<span style="font-family: Arial;">这时我们需要</span><span style="font-family: Arial;">在web.xml中配置错误页面</span>
<span style="font-family: Arial;"></span><pre name="code" class="java"><span style="white-space:pre"></span><error-page><error-code>404</error-code><location>/error/404error.html</location></error-page>这样其实就可以啦,但是部分用户调试时发现web.xml这个没起作用,也没有跳转到指定的error页面。
<span style="font-family: Arial;"><span style="white-space:pre"></span>而是显示这个页面(当时就困扰我一下午)</span>
<span style="font-family: Arial;"><img src="http://img.blog.csdn.net/20160404233928964?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></span>
<span style="font-family: Arial;">别急:这是浏览器对错误页面进行优化导致的,只需要</span>
<span style="font-family: Arial;"><span style="color: rgb(50, 62, 50); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(127, 163, 206);">在IE</span><span style="color:#FF0000;word-wrap: normal; word-break: normal; line-height: 21px; font-family: simsun; font-size: 14px; background-color: rgb(127, 163, 206);">工具</span><span style="color: rgb(50, 62, 50); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(127, 163, 206);">-></span><span style="color:#FF0000;word-wrap: normal; word-break: normal; line-height: 21px; font-family: simsun; font-size: 14px; background-color: rgb(127, 163, 206);">Internet选项</span><span style="color: rgb(50, 62, 50); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(127, 163, 206);">-></span><span style="color:#FF0000;word-wrap: normal; word-break: normal; line-height: 21px; font-family: simsun; font-size: 14px; background-color: rgb(127, 163, 206);">高级</span><span style="color: rgb(50, 62, 50); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(127, 163, 206);">中将</span><span style="color:#FF0000;word-wrap: normal; word-break: normal; line-height: 21px; font-family: simsun; font-size: 14px; background-color: rgb(127, 163, 206);">显示友好http错误提示</span><span style="color: rgb(50, 62, 50); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(127, 163, 206);">的前面的勾取消,ok了。</span></span>
0 0
- Struts2中自定义404错误页面
- struts2自定义404错误页面
- struts2自定义404错误页面
- Thinkphp 中自定义404错误页面
- 自定义404错误页面
- Tomcat中404/500 错误,自定义错误页面
- struts2开发中出现404页面找不到错误
- 在Tomcat中配置404自定义错误页面全解
- 在Tomcat中配置404自定义错误页面全解
- 在Tomcat中配置404自定义错误页面
- 在Tomcat中配置404自定义错误页面全解
- Laravel5.4中自定义404、503等错误页面
- Struts2——错误页面的自定义配置详解
- 自定义Tomcat 404错误页面
- nginx自定义404错误页面
- APACHE_自定义404错误页面
- asp.net中自定义错误处理页面
- asp.net中自定义错误处理页面
- spring与mybasic整合配置
- PHP的PSR规范中文版
- centos7下安装telnet服务器
- 全面分析 Spring 的编程式事务管理及声明式事务管理
- 17. 促销,市场营销和内容页
- Struts2中自定义404错误页面
- 将中文字符串分割为数组 解决str_split中文乱码php
- VirtualBox installation failure on Windows
- PHP基础语法讲解
- 匿名内部类,只使用一次
- 数字排序
- android高级---->Handler的原理
- HTTP 304状态分析
- filter_var() 验证邮箱、ip、url的格式 php