struts2 错误提示页面

以前做的一个网站,最近服务器后台出现一些异常,问题是客户访问一个该网站下不存在的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 控制台打印异常信息。

原文地址:https://www.cnblogs.com/mengziHEHE/p/4663860.html