以下代码展示了如何在 Struts2 的 web.xml 配置文件中添加 404 错误页面跳转到 error404.jsp。

<?xml version='1.0' encoding='UTF-8'?>
<web-app xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://xmlns.jcp.org/xml/ns/javaee' xsi:schemaLocation='http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd' version='3.1'>
  <display-name>NO_12ALL</display-name>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <error-page>
    <error-code>404</error-code>
    <location>/error404.jsp</location>
  </error-page>
</web-app>

通过添加 `` 节点,并设置 `` 为 404,`` 为 `/error404.jsp`,就可以实现当出现 404 错误时,自动跳转到 error404.jsp 页面。


原文地址: https://www.cveoy.top/t/topic/fxhH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录