URLWRITE view Rewriting Technology and urlwrite view Rewriting
UrlRewrite is the address rewriting. All the URLs you get are processed URLs, similar to Apache mod_rewrite. Converting our dynamic webpage addresses to static ones, such as html and shtml, can also hide the real path of the webpage.
It has the following features:
1. Improved security and hidden URLs
2. Beautifying URLs, facilitating search engine revenue and increasing traffic
Download the jar package
Web: http://central.maven.org/maven2/org/tuckey/urlrewritefilter/
You can see the jar packages of various versions of urlwritefilter.
Import the Jar package to the project after it is downloaded.
Create a urlrewrite. xml file
<? 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>
<Rule>
<From>/([a-za-z?##.html </from>
<To last = "true">/$ 1.jsp</to>
</Rule>
</Urlrewrite>
// The dtd file has only two digits, for example, 4.0.2/4.0.3/4.0.4, and only urlrewrite4.0.dtd
Rule is a url rewriting rule, from is the displayed address, to is the actual address of the ing, $1 is the rewriting parameter, and its value is one-to-one correspondence with the regular expression in from, there can be multiple regular expressions that match the regular expression (). The regular expression ^ specifies the character string to start and $ indicates the end. <rule> <from> /(. *)/login.html </from> <to type = "forward">/yui/login.html? Name = $1 </to> </rule>
<Rule>
<From> ^/user/([a-z] +)/([0-9] +) $ </from>
<To>/index. jsp? Nickname = $1 & amp; age = $2 </to>
</Rule>
For example, the actual request url of http: // localhost: 8080/app/abc/login.html is http: // localhost: 8080/app/yui/login.html? Name = abc
The more advanced the rule, the more effective it takes.
Configure the web. xml file
<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>