Spring URL Rewrite

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.