tomcat struts2 404 配置

2017-10-11 Frank Java

<url-pattern>*.html</url-pattern> web.xml里设置了html后缀样式,非html后缀的<error-page> 会生效,注意这里的<location>不能设置404.html了。
html后缀的会进入struts。struts配置后,不存在的控制器会访问配置的页面。控制器存在,action不存在的通过过滤器进行跳转。

web.xml

<web-app>
    <!--...-->
    <filter>
        <filter-name>Struts2</filter-name>
        <filter-class>

            com.liangyou.web.filter.RdStrutsFilter

        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Struts2</filter-name>
        <url-pattern>*.html</url-pattern>
        <url-pattern>*.htm</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <error-page>
        <error-code>401</error-code>
        <location>/404.jsp</location>
    </error-page>
    <error-page>
        <error-code>403</error-code>
        <location>/404.jsp</location>
    </error-page>
    <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/404.jsp</location>
    </error-page>
</web-app>

struts.xml

<default-interceptor-ref name="globalStack" />
<default-action-ref name="pagenotfound"/>
<action name="pagenotfound">
    <result type="ftl">/404.html</result>
</action>

评论:

用户5979662024
2018-03-11 11:52
<filter-mapping>
        <filter-name>Struts2</filter-name>
        <url-pattern>*.html</url-pattern>
        <url-pattern>*.htm</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
用户5979662024
2018-03-11 11:44
111
用户5979662024
2018-03-11 11:52
@用户5979662024:11

发表评论 登录

Top