明天的明天的明天

用键盘改变生活

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  17 Posts :: 0 Stories :: 19 Comments :: 0 Trackbacks
首先要在web.xml中声明一个Filter
 <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>

然后在WEB-INF目录下新建urlrewrite.xml
在其中进行重写规则的定义,它使用正则表达式来进行规则的定义

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
        "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">

<!--

    Configuration file for UrlRewriteFilter
    http://tuckey.org/urlrewrite/

-->
<urlrewrite>

        <rule>
            <from>/test.html</from>
            <to type="redirect">%{context-path}/page.html</to>
        </rule>

        <rule>
            <from>/param/(.*)</from>
            <to>/param.jsp?param=$1</to>
        </rule>

</urlrewrite>

上面是我的一个简单的测试
        <rule>
            <from>/test.html</from>
            <to type="redirect">%{context-path}/page.html</to>
        </rule>
是将test.html的访问请求转发给page.html

        <rule>
            <from>/param/(.*)</from>
            <to>/param.jsp?param=$1</to>
        </rule>
将param.jsp?param=111这种请求重写为/param/111

里面有详细的例子,大家可以自己看下
posted on 2007-09-17 12:52 Endless 阅读(519) 评论(0)  编辑  收藏

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


网站导航: