Url Rewrite Filter
Url Rewrite Filter 是一个基于java的 url rewirte开源项目,功能类似Apache中的rewrite模块
一. 主要功能
a) 实现url地址的伪静态化
例如可以把http://localhost:8080/myindex.do?method=listIndex&user=ezplus的请求重定向或转发到http://localhost:8080/blog/ezplus,这样做就避免了url中出现?&之类的符号,而且页面伪静态化之后也增加了被搜索引擎找到的概率.
b) 根据配置文件自动转化页面上的连接
在写页面的时候程序员不用关心在页面中出现的url地址将被如何伪静态化,例如,程序员还是可以在写页面的时候使用http://localhost:8080/myindex.do?method=listIndex&user=ezplus, 通过在urlrewrite.xml中配置,既可以实现页面url地址自动转化为伪静态化后的地址,用户在查看页面源码的时候原http://localhost:8080/blog/ezplus将被自动替换为http://localhost:8080/blog/ezplus
二. 其他功能
……
三. 安装使用
a) 下载和安装 Tomcat
b) 部署你的应用
d) 解压 下载后的 urlrewritefilter-3.0.zip 到 \webapps\
e) 修改 web.xml 如下
<display-name>Url Rewrite</display-name>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
f) 修改 WEB-INF 下的 urlrewrite.xml:
/blog/([0-9]+)
/myindex.do?method=listIndex&user=$1
/myindex.do\?method=listIndex&user=([0-9]+)
<!--/stro-->(request.getContextPath()+"/myindex.do?method=listIndex&user=ezplus)%>这里我在”?”前加了转义符”/”,但是看网上很多文章上都不用加,我试过不加,但是总是报错,不知道为什么? -->
/blog/$1
response.encodeURL,也可以使用jstl中的标签