Urlrewritefilter Instructions for use

Source: Internet
Author: User

First, urlrewritefilter description and advantages

Urlrewritefilter, through the Java filter filter to rewrite the URL, the user gets all are processed URL address, essentially through the pseudo-address page jump, hide the real address, to achieve the purpose of hiding, haha.

Has the following advantages:
1: Improve security, you can effectively avoid some parameter name, ID and so completely exposed to the user, if the user casually lose, if not comply with the rules will directly return a 404 or error page, which is more than the direct return 500 or a lot of server error information better
2: Beautify the URL, remove those such as *.do,*.action , such as suffix name, long parameter string, etc., can organize their own streamlining to reflect the content of the URL to access the module

3: More conducive to search engine revenue, through the URL of some optimization, can make the search engine better identify and ingest the information of the site

Second, network resources

1. Official website: Http://tuckey.org/urlrewrite/google code:https://code.google.com/p/urlrewritefilter/

2. Instructions for use of the document: http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html

Third, the use of steps

1. Add the following code to Web. xml

<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>

2. Address mapping rules in the Urlrewrite.xml configuration file, using regular expressions

<?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><rule><from>^/newsinfo-list-([0-9]+). shtml$</from><to>/newsinfo.do? Method=list&amp;mod_id=$1</to></rule><outbound-rule><from>/newsinfo.do\?method= List&amp;mod_id= ([0-9]+) $</from><to>/newsinfo-list-$1.shtml</to></outbound-rule> </urlrewrite>

3. Use the following address in JSP

<c:url var= "url_1001001000" value= "/newsinfo.do?method=list&mod_id=1001001000"/> <li><a href= "$ {url_1001001000} ' > Test address </a></li>

The following methods of use are available in the official documents:

Using The example above JSP ' s with the code <a href= "<%= response.encodeurl ("/world.jsp?country=usa&amp;city= NYC ")%>" >nyc</a> would output <a href= "/world/usa/nyc" >nyc</a>or JSTL <a href= "<c:url Value= "/world.jsp?country=${country}&amp;city=${city}"/> ">nyc</a> 'll output <a href="/world/ Usa/nyc ">nyc</a>note, If you is using JSTL (ie, <c:url) this would work also.

4. Basic Principles

JSP page address--Server Filter--Call urlrewrite.xml mapping rule--Server response--Convert to pseudo address

5, Summary: Easy to learn and use, Urlrewritefilter is the perfect choice for address hiding in Java Web development.

Urlrewritefilter Instructions for use

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.