gembin

OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

HBase, Hadoop, ZooKeeper, Cassandra

Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

About Me

 

JSP使用URLRewirte实现url地址伪静态化(转)

URL:http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.1/index.html
URLRewirte的用处:
1.满足搜索引擎的要求
2.隐藏技术实现,提高网站的移植性
3.满足美感的要求(个人感觉这个用处太牵强)
项目部署
1.首先在http://tuckey.org/urlrewrite/下载urlrewirtefilter
2.解压所下载的文件,把urlrewrite-2.6.0.jar复制到项目的WebRoot/WEB-INF/lib/目录下,然后编译
3.把urlrewrite.xml复制到项目的WebRoot/WEB-INF/目录下
4.在web.xml文件中加入以下:
<!-- 动态地址静态化 -->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
   <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
   <init-param>
    <param-name>logLevel</param-name>
    <param-value>WARN</param-value>
   </init-param>
</filter>
<filter-mapping>
   <filter-name>UrlRewriteFilter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>
5.需要配置urlrewrite.xml文件来实现url静态化,下面将详细说明
到这里相关的配置已经完成,下面看如何把动态地址静态化
1.普通url静态化
例如:要把http://localhost/prjtest/user/list.jsp转换成http://localhost/prjtest/user/list.html
这种是最简单的,当一个servlet跳转到list.jsp页面列出user列表时,在urlrewrite.xml中这样配置:
<rule>
<from>^/user/list.html</from>
   <to>/user/list.jsp</to>
</rule>
当请求/user/list.html这个页面时,实际上相当于请求/user/list.jsp页面
在servlet的跳转要这样写:
response.sendRedirect("./user/list.html");
2.带参数的url静态化
例如:要把http://localhost/prjtest/user/view.jsp?cid=1&cname=admin转换成
       http://localhost/prjtest/user/view/1_admin.html
在urlrewrite.xml中这样配置:
<rule>
<from>^/user/view/([0-9]+)_([a-z]+).html$</from>
<to>/user/view.jsp?cid=$1&amp;cname=$2</to>
</rule>
当请求/user/view/1_admin.html这个页面时,实际上相当于请求/user/list.jsp?cid=1&cname=admin页面
在servlet的跳转要这样写(cid,cname为变量):
response.sendRedirect("./user/view/"+ cid +"_"+ cname +".html");
注意:配置文件中用"&amp;"来代替"&"

一个通用的正则表达式:[a-zA-Z0-9]+



posted on 2008-05-27 00:44 gembin 阅读(1283) 评论(0)  编辑  收藏 所属分类: JavaEE


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(6)

随笔分类(440)

随笔档案(378)

文章档案(6)

新闻档案(1)

相册

收藏夹(9)

Adobe

Android

AS3

Blog-Links

Build

Design Pattern

Eclipse

Favorite Links

Flickr

Game Dev

HBase

Identity Management

IT resources

JEE

Language

OpenID

OSGi

SOA

Version Control

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

free counters