urlrewrite的简单搭建

   urlrewrite的简单搭建过程,它的使用优点以及详细使用网上有很多资料,可以直接去查找。
以下就直接介绍如果把urlrewrite加入到自己的项目工程中;

1、下载jar包:urlrewritefilter-4.0.3.jar 到项目/WEB-INF/lib下,如果是maven项目,加入依赖:

<dependency>
    <groupId>org.tuckey</groupId>
    <artifactId>urlrewritefilter</artifactId>
    <version>4.0.3</version>
</dependency>

2、在项目/WEB-INF/web.xml 合适的位置加入一下代码:
<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>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

3、在WEB-INF新加入:urlrewrite.xml内容信息可以参照官网的信息:
如:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
        "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
    <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>
</urlrewrite>


这样几部urlrewriter就加入到了项目中。


附件中包含了jar包和urlrewrite.xml。
urlrewrite官方网址:
http://tuckey.org/urlrewrite/

你可能感兴趣的:(urlrewrite)