注册 X
我已阅读并同意  服务条款
首页 > IT技术笔记 > 查看笔记

SSM使用urlrewrite实现地址栏静态化

1、  添加依赖

<!-- urlrewrite依赖 -->

<dependency> 

<groupId>org.tuckey</groupId>

<artifactId>urlrewritefilter</artifactId>

<version>4.0.3</version>

</dependency>

2、  Web.xml配置

<!--配置Url RewriteFilter -->

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

     <!--配置Url RewriteFilter拦截所有请求-->

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

    <to type="forward">/list.jsp</to>   

    <from >/index.jsp</from>      

    <!-- 前台访问http://localhost.:808/index.jsp,地址拦无变化,页面显示的内容是show.jsp --> 

  </rule>

 

</urlrewrite>

 

<to type="forward">中的type有两个值,默认的是 type="forward".连接外部的网站时用type="redirect"。

 

 

<rule>

    <to type="forward">/noteController/toList.action?fenlei=$1&amp;pages=$2</to>

    <from >^/forum-(\w+)-(\d+)\.html$</from>

</rule>

 

<!-- http://localhost.:808/forum-jisubiji-2.html实际访问noteController/toList.action?fenlei=jisubiji&amp;pages=2 -->

 

   <rule>

      <from >^/resourcelist/(\w+)/([a-zA-Z0-9_%]+)/(\d+)\.html$</from>

      <to type="forward">/resourceController/toList.action?notetype=$1&amp;keyword=$2&amp;pages=$3</to>

  </rule>

 

   <rule>

      <from >^/resourcelist/(\w+)/([^_\/\.]+)/(\d+)\.html$</from>

      <to type="forward">/resourceController/toList.action?notetype=$1&amp;keyword=$2&amp;pages=$3</to>

  </rule>

 

([^_\/\.]+)/(\d+)表示只要不是^_\/\.这些字符都能进行匹配



 打赏        分享



评论