1

我有一个关于 urlrewritefilter 的问题,直到现在我在网上找不到任何关于它的信息。

我想在 Tomcat7 中重定向一个 http POST。这是一个例子......

该调用是对 ULR 的 HTTP POST,例如

http://localhost:8080/oldApplication/Example?a=123&b=2

此调用还包含一些内容,如 xml 或 json。过滤器配置良好,并且 urlrewrite.xml 包含:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">

<urlrewrite use-query-string="true">
    <rule>
        <condition type="method">POST</condition>
        <from>^(.*)$</from>
        <to type="redirect">/newApplication$1</to>
    </rule>
</urlrewrite>

在访问日志中,我可以看到调用

http://localhost:8080/oldApplication/Example?a=123&b=2

被重定向到

http://localhost:8080/newApplication/Example?a=123&b=2

到现在还好。问题是重写改变了方法,因此新的 url 被 HTTP GET 而不是 HTTP POST 调用。我试图在该方法上添加一个条件,但在重写后仍然得到一个 HTTP GET。

有人知道如何配置重写过滤器来避免这种情况吗?

4

1 回答 1

3

您正在使用类型属性重定向type="redirect"

该属性等价于HttpServletResponse.sendRedirect()实际使用该GET方法向目的地发起新请求,因此所有参数都与HTTP方法一起丢失。

如果未通知,此属性的默认值forward相当于HttpServletRequest.getRequestDispatcher(url).forward()

转发将保留所有请求参数以及 HTTP 方法。

因此,为了获得所需的结果,您必须省略 type 属性或将其设置为forward.

<to>/newApplication$1</to>

或者

<to type="forward">/newApplication$1</to>
于 2016-06-06T18:29:42.180 回答