使用 URLRewrite 重写URL

来源:互联网 发布:大道知世cos正片 编辑:程序博客网 时间:2024/06/02 22:57

1、测试环境

 

     下载 URLRewrite,以版本3.1.0为例,将urlrewrite-3.1.0.jar放到classpath下;将下载的文件中的urlrewrite.xml文件放到

     /WEB-INF/下,注意不要修改urlrewrite.xml文件名。

 

2、修改web.xml

 

     在web.xml中增加filter配置:

 

 

    <init-param />,<dispatcher />为可选项。

 

3、修改urlrewrite.xml

 

 

 

  其中 <rule />是定制的规则,<from />是显示的url,<to />是真正请求的url。type = "forward" 地址栏显示from部分(静态化url),type="redirect",地址栏显示to部分(真正请求的地址),注意要保证路径的正确。规则的定制支持正则表达式(如rule 2)。

 

4、测试

 

     测试环境文件目录

      WebRoot

         ---WEB-INF

               ---urlrewrite.xml

         ---login.jsp

 

      启动服务,地址栏输入http://localhost:port/xxx/login.html

 

      rule 1:实际请求为http://localhost:port/xxx/login.jsp

      rule 2:实际请求为http://localhost:port/xxx/login.jsp?id=login

 

     总结:要熟悉正则表达式的运用

 

原创粉丝点击