jsp伪静态--url rewrite

第一步:首先到这里下载http://tuckey.org/urlrewrite/  稳定版:urlrewrite-2.6.0.jar

第二步:将urlrewrite-2.6.0.jar 放到tomcat的lib目录下。

第三步:将urlrewrite-2.6.0.jar 放到Netbeans的工程目录下的Web-inf/Lib文件夹中。

同时把urlrewrite.xml 放到Web-inf文件夹中,如图:

WEB-INF
    –lib
       –urlrewrite-2.6.0.jar
    –urlrewrite.xml

第四步:修改Web-inf文件夹中的Web.xml   在 <servlet-mapping>前面加入

  1. <filter>
  2.   <filter-name>UrlRewriteFilter</filter-name>
  3.   <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
  4.   <init-param>
  5.     <param-name>logLevel</param-name>
  6.     <param-value>debug</param-value>
  7.   </init-param>
  8. </filter>
  9. <filter-mapping>
  10.   <filter-name>UrlRewriteFilter</filter-name>
  11.   <url-pattern>/*</url-pattern>
  12. </filter-mapping>

第五步:

修改urlrewrite.xml,在urlrewrite节点中添加一条规则,如下

 <rule>
  <from>/home</from>
  <to type= "forward" >/index.jsp</to>
 </rule>

 

重启Tomcat,重新编译项目,部署,运行。ok。


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>


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>/news([a-z0-9]+).html</from>
        <to>/newsget.do?id=$1</to>
    </rule>
 <!--
 <rule>
        <from>/user/([a-z0-9]+)/([a-z0-9]+).html</from>
        <to>/user.action?id=$1&sName=$2</to>
    </rule>


    <rule>
        <note>
            The rule means that requests to /test/status/ will be redirected to /rewrite-status
            the url will be rewritten.
        </note>
        <from>/test/status/</from>
        <to type="redirect">%{context-path}/rewrite-status</to>
    </rule>


    <outbound-rule>
        <note>
            The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
            the url /rewrite-status will be rewritten to /test/status/.

            The above rule and this outbound-rule means that end users should never see the
            url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
            in your pages.
        </note>
        <from>/rewrite-status</from>
        <to>/test/status/</to>
    </outbound-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.

    -->

</urlrewrite>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值