Java URLrewrite 过滤器找不到匹配项
我正在使用 tuckey 的 URLRewrite 过滤器 ( http://www.tuckey.org/urlrewrite/ )
现在我创建了一些规则,但有一种情况让我头疼。 URL:/group/1/update 应重写为:/group?id=1&action=update
我为此例创建了一个正则表达式模式: ^/group/([0-9]+)/(\w*)$,但过滤器无法重写它。没有匹配项。
在我的测试用例中,我在所有模式中运行了这个 url,只是为了检查。我找到了符合我预期的比赛。
assertFalse( "/group/1/update".matches("^/group/create$") );
assertFalse( "/group/1/update".matches("^/group/save$") );
assertFalse( "/group/1/update".matches("^/group/([0-9]+)/?$") );
assertTrue( "/group/1/update".matches("^/group/([0-9]+)/(\\w*)$") );
assertFalse( "/group/1/update".matches("^/group/([0-9]+)/(\\w*)\\?(.*)+$") );
那么为什么过滤器找不到规则呢?
只是为了包含所有内容,这是我的 urlrewrite.xml 或其中的一部分:
<rule>
<from>^/group/create$</from>
<to>/group?action=create</to>
</rule>
<rule>
<from>^/group/save$</from>
<to>/group?action=save</to>
</rule>
<rule>
<from>^/group/([0-9]+)/?$</from>
<to>/group?id=$1&action=show</to>
</rule>
<rule>
<from>^/group/([0-9]+)/(\\w*)$</from>
<to>/group?id=$1&action=$2</to>
</rule>
<rule>
<from>^/group/([0-9]+)/(\\w*)\\?(.*)+$</from>
<to>/group?id=$1&action=$2&$3</to>
</rule>
再见
Adrian
I am using the URLRewrite Filter from tuckey ( http://www.tuckey.org/urlrewrite/ )
Now i created some rules, but there is one case which gives me headaches.
The URL: /group/1/update should be rewritten as: /group?id=1&action=update
I created a regexp Pattern for this case: ^/group/([0-9]+)/(\w*)$, but the Filter is unable to rewrite it. There is no match.
Inside my TestCase i ran this url through all my patterns, just to check. And i found the match as i expected.
assertFalse( "/group/1/update".matches("^/group/create$") );
assertFalse( "/group/1/update".matches("^/group/save$") );
assertFalse( "/group/1/update".matches("^/group/([0-9]+)/?$") );
assertTrue( "/group/1/update".matches("^/group/([0-9]+)/(\\w*)$") );
assertFalse( "/group/1/update".matches("^/group/([0-9]+)/(\\w*)\\?(.*)+$") );
So how come the Filter is unable to find a Rule?
Just to include everything, here is my urlrewrite.xml, or part of it:
<rule>
<from>^/group/createlt;/from>
<to>/group?action=create</to>
</rule>
<rule>
<from>^/group/savelt;/from>
<to>/group?action=save</to>
</rule>
<rule>
<from>^/group/([0-9]+)/?lt;/from>
<to>/group?id=$1&action=show</to>
</rule>
<rule>
<from>^/group/([0-9]+)/(\\w*)lt;/from>
<to>/group?id=$1&action=$2</to>
</rule>
<rule>
<from>^/group/([0-9]+)/(\\w*)\\?(.*)+lt;/from>
<to>/group?id=$1&action=$2&$3</to>
</rule>
Bye
Adrian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用单反斜杠
\
而不是双反斜杠\\
。在 Java 代码中,双反斜杠用于表示单个反斜杠。由于字符串是从外部文件读取的,因此不需要转义反斜杠。
You should use single backslash
\
instead of double backslash\\
.In Java code, the double backalsh is used to represent a single backslash. Since the string is read from external file, there is no need the escape the backslash.