struts2 404处理
目前在做一个网络应用程序,struts2 + spring + hibernate,服务器是tomcat。希望用户在IE地址栏乱敲的时候,所敲入的所有未定义的URL都能被程序捕捉到,然后转到一个自制的404错误处理页面。
首先查阅网上的资料,得知可以在web.xml中加入这么一段:
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>
这样,所以未找到的404错误都会转到/error/404.jsp接受处理。
但是经过试验,我发现以.action结尾的URL会先被struts2框架所捕获,而不会直接转入web.xml中配置的处理页面。这样,如果在struts.xml没有配置相应的action,则会在tomcat里输出错误:
严重: Could not find action or result
There is no Action mapped for namespace / and action name ******. - [unknown location]
虽然最后也能转入web.xml中配置的处理页面,但是这样在命令台瞎输出一些东西,非常不便于程序的管理和调试,所以还得想办法让struts2框架处理未定义的action。
查阅网上资料,发现可以在struts.xml中,添加一个默认的package,然后在这个默认的package中,添加一个默认的action,让这个action转向404错误处理页面:
<package name="default" extends="struts-default">
<default-action-ref name="notFound" />
<action name="notFound">
<result>/error/404.jsp</result>
</action>
</package>
默认的package的特点就在于不定义namespace属性,这样所有未定义的namespace都会转向这里。name="default"是为了便于阅读,其实name是什么都可以,也可以为空:name=""。
然后还要在其它已定义的package中也添加默认的action,转向404错误处理页面。这样就可以完全处理所有的404错误了。
网友评论:
<global-results>
<result name="notFound">/404.html</result>
</global-results>,也可以
struts2 404处理的更多相关文章
- struts2 404错误
action类必须放在xxxx.xxx.xxx.xxx.action 包下才可以.
- struts2完全捕获404错误的方法
目前在做一个网络应用程序,struts2 + spring + hibernate,服务器是tomcat.希望用户在IE地址栏乱敲的时候,所敲入的所有未定义的URL都能被程序捕捉到,然后转到一个自制的 ...
- 路径名称和struts.xml配置不一致导致struts2报404
struts.xml中写的是<result name="...">authorityInterceptor/xxx.jsp</result> 但是实际的文件 ...
- Struts2 Handle 404 error page and wrong action
1. To handle 404 not found yourself, just add this code to your web.xml <error-page> <error ...
- <welcome-file>index.action</welcome-file>直接设置action,404和struts2中的解决方案
这几天的项目页面的访问全部改为.action访问,在修改首页时遇到了问题.将web.xml文件中<welcome-file>index.action</welcome-file> ...
- struts2 第一次使用 404 页面引发的一系列问题
环境:ubuntu . eclipse.struts-2.3.24 问题描写叙述: 1. struts2 訪问出现404 2. 严重: Exception starting filter Str ...
- struts2中<welcome-file>index.action</welcome-file>直接设置action,404的解决方案
这几天的项目页面的访问全部改为.action访问,在修改首页时遇到了问题.将web.xml文件中<welcome-file>index.action</welcome-file> ...
- struts2中怎样处理404?
眼下在做一个网络应用程序,struts2 + spring + hibernate,server是tomcat.希望用户在IE地址栏乱敲的时候.所敲入的全部没有定义的URL都能被程序捕捉到,然后转到一 ...
- 配置Struts2后运行jsp出现404的解决方法
更新:善用控制台查看错误信息 --------------------------------------------- 原因:Java Build Path没有导入正确的jar包或者导入了但没有把相 ...
随机推荐
- hdu 素数环
算法:搜索 题意:相邻的两个数之和是素数,别忘了最后一个,和第一个 Problem Description A ring is compose of n circles as shown in dia ...
- 搭建hbase-0.94.26集群环境
先安装hadoop1.2.1,见http://blog.csdn.net/jediael_lu/article/details/38926477 1.配置hbase-site.xml <prop ...
- HTML中select标签单选多选详解
select 元素可创建单选或多选菜单.当提交表单时,浏览器会提交选定的项目,或者收集用逗号分隔的多个选项,将其合成一个单独的参数列表,并且在将 <select> 表单数据提交给服务器时包 ...
- windows安装配置mysql-5.7.13-winx64方法
1.mysql-5.7.13-winx64.zip下载 官方下载地址:http://dev.mysql.com/downloads/mysql/ 2.解压到D:\mysql\mysql-5.7.13- ...
- [LA] 3644 - X-Plosives [并查集]
A secret service developed a new kind of explosive that attain its volatile property only when a spe ...
- Chrome小技巧:如何下载离线版安装文件
每当chrome有更新之后,都有不少用户想要下载离线版的安装文件,但苦于找不到下载地址而发愁,其实这个问题很简单,下面我来分享一下方法(仅针对Windows操作系统): 对于稳定版(正式版)Chrom ...
- 解决SQL server不支持utf8,php却用utf8的矛盾问题
function convert2utf8($string) { return iconv("gbk","utf-8",$string); } function ...
- 系统监控的工具tsar
近期一直在折腾着elasticsearch,需要对硬件进行评估 大概几方面 内存 cpu 硬盘 网络. iostat vmstat top 几个命令用了一堆,其实需要关注的几个点只要都列出来就可以了 ...
- 107个常用Javascript语句
1.document.write( " "); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document- >html- >(head,body ...
- 【转】Kconfig,Makefile 和 .config
原文网址:http://blog.csdn.net/nxh_love/article/details/11846861 最新在做Sensor驱动移植的时候,发现了Android driver 中有Kc ...