使用Url Rewrite Filter实现页面伪静态化

Url Rewrite Filter 是一个基于java url rewirte开源项目,功能类似Apache中的rewrite模块<o:p></o:p>

一.     主要功能<o:p></o:p>

a)         实现url地址的伪静态化<o:p></o:p>

例如可以把http://localhost:8080/myindex.do?method=listIndex&user=ezplus的请求重定向或转发到http://localhost:8080/blog/ezplus,这样做就避免了url中出现?&之类的符号,而且页面伪静态化之后也增加了被搜索引擎找到的概率.<o:p></o:p>

b)         根据配置文件自动转化页面上的连接<o:p></o:p>

在写页面的时候程序员不用关心在页面中出现的url地址将被如何伪静态化,例如,程序员还是可以在写页面的时候使用http://localhost:8080/myindex.do?method=listIndex&user=ezplus  通过在urlrewrite.xml中配置<outbound-rule></outbound-rule>,既可以实现页面url地址自动转化为伪静态化后的地址,用户在查看页面源码的时候原http://localhost:8080/blog/ezplus将被自动替换为http://localhost:8080/blog/ezplus<o:p></o:p>

二.     其他功能<o:p></o:p>

……<o:p></o:p>

三.     安装使用<o:p></o:p>

a)         下载和安装 Tomcat<o:p></o:p>

b)         部署你的应用<demo app=""></demo><o:p></o:p>

c)         下载  Url Rewrite Filter http://tuckey.org/urlrewrite/<o:p></o:p>

d)         解压 下载后的 urlrewritefilter-3.0.zip <tomcat_home></tomcat_home>\webapps\<demo app=""></demo><o:p></o:p>

e)         修改 web.xml 如下<o:p></o:p>

?xml version=”1.0″ encoding=”UTF-8″?
web-app id=”WebApp_9″ version=”2.4″ xmlns=”http://java.sun.com/xml/ns/j2ee
         xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
         xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
<o:p></o:p>

display-nameUrl Rewrite/display-name<o:p></o:p>

filter
       
filter-nameUrlRewriteFilter/filter-name
       
filter-classorg.tuckey.web.filters.urlrewrite.UrlRewriteFilter/filter-class
   
/filter
   
filter-mapping
       
filter-nameUrlRewriteFilter/filter-name
       
url-pattern/*/url-pattern
   
/filter-mapping
   
/web-app<o:p></o:p>

f)           修改 WEB-INF 下的 urlrewrite.xml<o:p></o:p>

<rule></rule><o:p></o:p>

        <from></from>/blog/([0-9]+)<o:p></o:p>

        <to></to>/myindex.do?method=listIndex&user=$1<o:p></o:p>

<o:p></o:p>

<outbound-rule></outbound-rule><o:p></o:p>

         <from></from>/myindex.do\?method=listIndex&user=([0-9]+)<o:p></o:p>

             (request.getContextPath()+"/myindex.do?method=listIndex&user=ezplus)%>这里我在”?”前加了转义符”/”,但是看网上很多文章上都不用加,我试过不加,但是总是报错,不知道为什么?  --><o:p></o:p>

          <to></to>/blog/$1<o:p></o:p>

 <o:p></o:p>

8.  jsp页面中原来使用http://localhost:8080/myindex.do?method=listIndex&user=ezplus的地方现改为<o:p></o:p>

response.encodeURL

这里一定要使用response.encodeURL否则<outbound-rule></outbound-rule>不起作用<o:p></o:p>

也可以使用jstl中的<c:url></c:url>标签

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值