java urlrewrite

来源:互联网 发布:2016淘宝类目销量排名 编辑:程序博客网 时间:2024/06/05 02:46

加入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>logLevel</param-name>              <param-value>WARN</param-value>           </init-param>       </filter>

 

<filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern><dispatcher>REQUEST</dispatcher>    <dispatcher>FORWARD</dispatcher>    <dispatcher>INCLUDE</dispatcher></filter-mapping>
 
  <filter-mapping>         <filter-name>UrlRewriteFilter</filter-name>         <url-pattern>/*</url-pattern>         <dispatcher>REQUEST</dispatcher>         <dispatcher>FORWARD</dispatcher>    </filter-mapping> 

 

再在WEB-INFO下加入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"><urlrewrite use-query-string="true">    <!--    <rule>        <from>^/index.html$</from>        <to>/index.action</to>    </rule>    <outbound-rule>        <from>/index.action</from>        <to>/index.html</to>    </outbound-rule>        -->    <rule>        <from>^/bbs$</from>        <to>/showMainModule.action</to>    </rule>    <outbound-rule>        <from>/showMainModule.action</from>        <to>/bbs</to>    </outbound-rule>        <!--     showModuleById.action?fmid=3    showVddetail.action\?vdid=([0-9]+)    -->            <rule>        <from>^/bbs/board-([0-9]+)-([0-9]+)$</from>        <to>/showModuleById.action?fmid=$1&amp;pageNo=$2</to>    </rule>    <outbound-rule>        <from>/showModuleById.action\?fmid=([0-9]+)&amp;pageNo=([0-9]+)</from>        <to>/bbs/board-$1-$2</to>    </outbound-rule>        <!-- 最少匹配写在最下面,因为匹配时从上往下 -->    <rule>        <from>^/bbs/board-([0-9]+)$</from>        <to>/showModuleById.action?fmid=$1</to>    </rule>    <outbound-rule>        <from>/showModuleById.action\?fmid=([0-9]+)</from>        <to>/bbs/board-$1</to>    </outbound-rule>            <!-- http://localhost/club/bbs/showPostsById.action?fpid=10300# -->    <rule>    <from>^/bbs/posts-([0-9+])$</from>    <to>/showPostsById.action?fpid=$1</to>    </rule>                <outbound-rule>        <from>/show.do\?id=([0-9]+)&amp;data=([0-9]+)</from>        <to>/show_$1_$2.html</to>    </outbound-rule>    </urlrewrite>

 

jsp页面中:

<a href='<c:url value="/showModuleById.action?fmid=${forumModuleVo.forumModule.fmid }" />'>${forumModuleVo.forumModule.fmmname }</a>

 

其中,<c:url value="" /> 已经包含了上下文路径

 

 

 

 

 

  • urlrewrite-3.2.0.jar (193.8 KB)
  • 下载次数: 0
原创粉丝点击