struts2自定义404错误页面

来源:互联网 发布:电脑网络参数在哪里 编辑:程序博客网 时间:2024/05/22 12:08
 
struts2自定义404错误页面[转]
2011-02-17 10:20

以前做的一个网站,最近服务器后台出现一些异常,问题是客户访问一个该网站下不存在的action,为了给客户一个友好的界面提示以及减小服务器端日志文件的内容。就在struts2下进行了如下配置:

在struts.xml里的package下添加:

<default-action-ref name="pagenotfound"></default-action-ref> 
   <action name="pagenotfound"> 
              <result>/resourceNotFound.html</result> 
   </action>

 

当然struts2只会处理用户访问不存在的action,当用户访问jsp或者html时,是不会处理的。

这样还要在项目的web.xml下添加:

<error-page>
 <error-code>404</error-code>
 <location>/resourceNotFound.html</location>
</error-page>

 

本来以为只要在we.xml添加就行了,但是在我的机器上如果不在struts.xml添加

<default-action-ref name="pagenotfound"></default-action-ref> 
   <action name="pagenotfound"> 
              <result>/resourceNotFound.html</result> 
   </action>

 

仍然会在tomcat 控制台打印异常信息。


原创粉丝点击