如何使用 URLRewriting 过滤器向传入请求添加 .do 扩展名

问题描述 投票:0回答:1

我刚刚从 http://tuckey.org/ 安装了 URL 重写过滤器。

我添加了一条规则,为来自特定路径的请求添加

.do
/beta

  <rule>
        <from>(.*)/beta/(.*)\?(.*)</from>
        <to>$1/beta/$2.do\?$3</to>
    </rule>

    <rule>
        <from>(.*)/beta/(.*)</from>
        <to>$1/beta/$2.do</to>
    </rule>

规则配置进入状态

OK
,因此已成功加载。

不幸的是,现在我在日志中看到一个超过 5000 行的异常堆栈跟踪,并且似乎陷入了循环。

017-03-08 13:50:15.827 [0.0-8080-1] ERROR JSPException              [0966E] Exception trapped when showing Error Page! Filter execution threw an exception
javax.servlet.ServletException: Filter execution threw an exception
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:259) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: 

然后继续...

servlets url-rewriting servlet-filters url-mapping tuckey-urlrewrite-filter
1个回答
2
投票

似乎您的规则递归循环,因为目标 URL 与

<from>
子句中的正则表达式匹配。尝试重写正则表达式以仅匹配
from
表达式,而不是
to
结果网址。即

<rule>
    <from>(.*)/beta/(.*)</from>
    <to>$1/beta2/$2.do</to>
</rule>

有关更多详细信息,请参阅本指南初学者的 URL 重写

© www.soinside.com 2019 - 2024. All rights reserved.