<outbound-rule> element

Zero or more. This is very similar to a normal rule but it is used for rewriting urls that go through response.encodeURL().

Attribute Possible Value Explanation
enabled
(optional)
true (default) Enable this rule.
false Disable this rule.
encodefirst
(optional)
false (default) Run encodeURL() after running this outbound rule.
true Run encodeURL() before running this outbound rule.

May contain "run", "from", "to" and "set" element(s) also. Example:


<outbound-rule>
<from>^/world.jsp?country=([a-z]+)&amp;city=([a-z]+)$</from>
<to>/world/$1/$2</to>
</outbound-rule>

Using the example above JSP's with the code
<a href="<%= response.encodeURL("/world.jsp?country=usa&amp;city=nyc") %>">nyc</a>
will output
<a href="/world/usa/nyc">nyc</a>

Or JSTL
<a href="<c:url value="/world.jsp?country=${country}&amp;city=${city}" />">nyc</a>
will output
<a href="/world/usa/nyc">nyc</a>

Note, If you are using JSTL (ie, <c:url) this will work also.
URLREWRITE.XML

<? xml version="1.0" encoding="utf-8" ?>
<! DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.1.dtd"
>

< urlrewrite  use-query-string ="true" >
    
< rule >
        
< from > /show_([0-9]+)_([a-z]+).html </ from >
        
< to > /show.do?id=$1 &amp; data=$2 </ to >
    
</ rule >
    
< outbound-rule >
        
< from > /show.do\?id=([0-9]+) &amp; data=([a-z]+) </ from >
        
< to > /show_$1_$2.html </ to >
    
</ outbound-rule >

</ urlrewrite >

HTML:
< href ="<c:url value=" /show.do?id =111&data=rewrite" /> ">click me! </ a >

urlrewrite将show.do?id=111&data=rewrite自动写成show_111_rewrite.html,这样省掉了很多功夫,既有正向,又有逆向。

ExtJS教程- Hibernate教程- Struts2 教程- Lucene教程