1. Using MAVEN to download the relevant jar file, the Pom file is configured as follows:
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
</dependency>
2. Configure the Urlrewritefilter in Web. XML with the following configuration:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<!--because urlrewrite.xml can only be used under Web-inf, we may omit the Urlrewrite.xml path configuration here. -
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
3. Add the Urlrewirte.xml file and place the file in the Web-inf directory (it appears that the file can only be placed under Web-inf). The configuration is as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE urlrewrite Public "-//tuckey.org//dtd urlrewrite 3.2//en" "\\urlrewrite3.2.dtd" >
<urlrewrite>
<rule>
<note> rewrite loign.jsp into login.html</note>
<!--the path to the redireact in the controller--
<from>login.html</from>
<!--corresponding to the JSP file in the actual project---
<to type= "Forward" >/login.jsp</to>
</rule>
</urlrewrite>
4. The return content in the program controller is consistent with the contents of <from>, such as the following code slices are worth to be consistent with Urlrewrite:
@RequestMapping (value= "login.do")
Public String Login (httpservletrequest request, httpservletresponse response, role role) throws Exception {
if (Userservice.selectrolebynameandpassword (role)) {
Return "index";
} else {
return "redirect:login.html";
}
}
Spring URL Rewrite