温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

雪山飞鹄

温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

BlogJava 首页 新随笔 联系 聚合 管理
  215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
JAR版本:urlrewrite-3.2.0.jar
web.xml配置
    <filter>
        
<filter-name>UrlRewriteFilter</filter-name>
        
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
        
<init-param>
            
<param-name>confReloadCheckInterval</param-name>
            
<param-value>60</param-value>
        
</init-param>
        
<init-param>
            
<param-name>confPath</param-name>
            
<param-value>/WEB-INF/urlrewrite.xml</param-value>
        
</init-param>
     
</filter>
     
     
<filter-mapping>
         
<filter-name>UrlRewriteFilter</filter-name>
         
<dispatcher>REQUEST</dispatcher>
         
<dispatcher>FORWARD</dispatcher>
         
<url-pattern>/*</url-pattern>
     
</filter-mapping>
urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.2.dtd"
>

<!--

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

-->
<urlrewrite> 
    
<!-- 
        匹配地址为
        形如/content/94/list的地址将跳转到
        /IssuedContentAction.do?dispatch=vContentListBySubid&amp;scope=vmcontent&amp;columninfoid=$1
    
-->
    
<rule>
        
<!-- 地址栏显示的地址 -->
        
<from>/content/([0-9]+)/list</from>  
        
<!-- 真实的请求地址 -->
        
<to type="forward">/IssuedContentAction.do?dispatch=vContentListBySubid&amp;scope=vmcontent&amp;columninfoid=$1</to>
    
</rule>
    
<!--

    INSTALLATION

        in your web.xml add

        <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>

     EXAMPLES

     Redirect one url
        <rule>
            <from>/some/old/page.html</from>
            <to type="redirect">/very/new/page.html</to>
        </rule>

    Redirect a directory
        <rule>
            <from>/some/olddir/(.*)</from>
            <to type="redirect">/very/newdir/$1</to>
        </rule>

    Clean a url
        <rule>
            <from>/products/([0-9]+)</from>
            <to>/products/index.jsp?product_id=$1</to>
        </rule>
    eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.

    Browser detection
        <rule>
            <condition name="user-agent">Mozilla/[1-4]</condition>
            <from>/some/page.html</from>
            <to>/some/page-for-old-browsers.html</to>
        </rule>
    eg, will pass the request for /some/page.html on to /some/page-for-old-browsers.html only for older
    browsers whose user agent srtings match Mozilla/1, Mozilla/2, Mozilla/3 or Mozilla/4.

    Centralised browser detection
        <rule>
            <condition name="user-agent">Mozilla/[1-4]</condition>
            <set type="request" name="browser">moz</set>
        </rule>
    eg, all requests will be checked against the condition and if matched
    request.setAttribute("browser", "moz") will be called.

    
-->

</urlrewrite>
注意:
1、多个参数之间的连接符要用&amp;而不是&
2、匹配从应用程序的名称开始匹配

浏览器中显示的请求地址(请求链接中填写的地址)
/content/91/list
真正的请求地址
/IssuedContentAction.do?dispatch=vContentListBySubid&scope=vmcontent&columninfoid=91


posted on 2011-11-24 11:48 雪山飞鹄 阅读(838) 评论(0)  编辑  收藏 所属分类: struts2

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


网站导航: