web.xml 过滤器映射不转发到 struts [英] web.xml filter-mapping not forwarding to struts

查看:43
本文介绍了web.xml 过滤器映射不转发到 struts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些微不足道的事情,但看不到我遗漏了什么.我有以下 web.xml...

I am trying to do something trivial and can't see what I'm missing. I have the following web.xml...

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
</filter-mapping>

当我使用像 "http://localhost:8080/gallery.action 这样的 URL 时",一切正常(因为在 struts.xml 等中正确配置了gallery").

And when I use a URL like "http://localhost:8080/gallery.action", everything works just fine (because "gallery" is configured properly in struts.xml, etc, etc).

但是,如果我点击http://localhost:8080/gallery.do"相反 - 我收到了 404 响应.Tomcat 似乎没有将请求转发到 struts,因为 struts 端没有日志记录.Tomcat 日志只显示 404.

If, however, I hit "http://localhost:8080/gallery.do" instead - I get a 404 response. Tomcat does not appear to be forwarding the request to struts as there is no logging on struts side. Tomcat logs just show the 404.

我尝试将过滤器映射更改为 *.blah,但除了 *.action 外没有任何效果.我在默认的 web.xml 文件中没有看到任何冲突信息.

I've tried changing the filter-mapping to *.blah and nothing works except for *.action. I don't see any conflicting information in the default web.xml file.

有人知道我错过了什么吗?

Anyone know what I'm missing?

推荐答案

显然 Struts2 默认只识别 .action 扩展名,需要根据需要使用 struts.properties 文件配置其他扩展名:

Apparently Struts2 only recognizes the .action extension by default and one needs to configure other extensions as desired using struts.properties file:

struts.action.extension=action,do,etc

struts.action.extension=action,do,etc

鉴于大多数文档都讨论了如何专门使用过滤器映射来转发到 struts,这非常具有误导性.

This was very misleading given that most documentation discusses how to forward to struts using filter-mapping exclusively.

这篇关于web.xml 过滤器映射不转发到 struts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆