Jsp rewrite url, jsp rewrite

Source: Internet
Author: User

Jsp rewrite url, jsp rewrite

As we all know, all web sites produced by java webprogramming end with. JS, and all other websites end with. html. How can this effect be achieved? The reason for this article is that jsp rewrite url needs to be designed to a third-party shelf package urlrewritefilter. Here we provide

Urlrewritefilter

Import third-party racks in java

1. Place the urlrewrite-2.6.0.jar in the project's WEB-INF-> lib folder

2. Put urlrewrite. xml in the WEB-INF folder

 

3. Add in web. xml to load the UrlRewriteFilter class and intercept all access requests.

<Filter> <filter-name> UrlRewriteFilter </filter-name> <filter-class> org. tuckey. web. filters. urlrewrite. urlRewriteFilter </filter-class> </filter> <filter-mapping> <filter-name> UrlRewriteFilter </filter-name> <! -- Intercept all --> <url-pattern>/* </url-pattern> </filter-mapping>

4. modify the configuration in urlrewrite. xml

You do not need to worry about the rest. You only need to manage the content in the <rule> node. The configuration here is to rewrite the url rules.

<From> the address displayed on the browser appears to show users, such as xxx.html.

<To> the webpage address in the project directed by the cursor is actually accessed by xxx. jsp.

<From> write an interception rule in it. ^ indicates that the rule starts. $ indicates that the rule ends. () indicates a parameter. You can enter a regular expression in it. $1 indicates the first parameter.

For example, <from> ^/(. * example .html </from><To>/$ 1.jsp</to>Only the address ending with .html will be intercepted and converted to the actual address. (. *) indicates that any content can be entered.$1 indicates what the value in the brackets is.

For example, the actual access to/index.html is/index. jsp.

 

Note:

If <from> is filled in (. *), then your image path references various external resource paths.

If the address bar is followed by parameters, you can

<From> ^/(. * example .html? (. *) </From> the second (. *) is the format string of the concatenation parameter, for example,/index.html? Name = ''& id =''
<To>/$ 1.jsp? $2 </to> the second $2 is the value of the concatenation parameter, such as/index. jsp? Name = ''& id =''

 

At this point, the whole url has been rewritten. Please give us more advice on any shortcomings!

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.