如何在tuckey-urlrewrite-filter中配置url映射?

时间:2013-05-20 03:25:27

标签: java regex url-rewriting url-routing tuckey-urlrewrite-filter

我在webapps root下的一个文件夹项目中有一些关于.jsp,contact.jsp,user.jsp,index.jsp的页面。我使用tuckey-urlrewrite-filter进行url映射。 我用url写作

    <rule>
    <from>/contact_us</from>
        <to>/contact.jsp</to>
    </rule>
    <rule>
    <from>/about_us</from>
        <to>/about.jsp</to>
    </rule>

当我输入url about_us或contact_us时,这些都可以很好地打开相应的页面。 但我想为user.jsp添加除contact_us和about_us之外的任何东西。 因为我使用了user.jsp作为个人资料页面。 如果在url中输入“abhiramgiri”,user.jsp应该打开或者我输入的任何内容除了contact_us和about_us之外它应该打开user.jsp。我无法为这些案例编写实际代码。 Plz帮助我......

1 个答案:

答案 0 :(得分:0)

尝试将last =“true”设置为前两个规则,然后添加第三个规则:

<rule>
    <from>/contact_us</from>
    <to last="true">/contact.jsp</to>
</rule>
<rule>
    <from>/about_us</from>
    <to last="true">/about.jsp</to>
</rule>
<rule>
    <from>.*</from>
    <to>/user.jsp</to>
</rule>

这意味着,如果/ contact_us上有匹配项,那么过滤器将停止查找匹配项,同样适用于/ about_us。任何与这两者不匹配的东西都将与第三条规则进行比较,第三条规则应匹配任何东西。

在正则表达式中,“。”表示匹配任何单个字符,“*”表示匹配模式前一部分的零次或多次出现。所以“。*”表示匹配零个或多个任何字符。