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!