Urlrewrite implements URL rewriting in JSP

Source: Internet
Author: User

Urlrewrite, as its name implies, is to rewrite the URL. All users get are URLs that have been processed. I think there are three advantages: 1. improve security, this effectively prevents some parameter names and IDs from being completely exposed to users. If the user enters a random error and does not comply with the rules, a 404 or error page will be returned, this is better than directly returning 500 or a large number of server error messages. Two: beautify the URL and remove those such *. do and other extensions, long parameter strings, etc., can be organized and streamlined by themselves to better reflect the URL 3 of the access module content: more conducive to the search engine revenue, through some URL optimization, to enable the search engine to better identify and collect website information using urlrewrite, follow these steps. add the following configuration to xml: [xhtml] <filter> <filter-name> UrlRewriteFilter </filter-name> <filter-class> org. tuckey. web. filters. urlrewrite. urlRewriteFilter </filter-class> <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> [xhtml] <filter> <filter-name> UrlRewriteFilter </filter-name> <filter-class> org. tuckey. web. filters. urlrewrite. urlRewriteFilter </filter-class> <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> In fact, urlrewrite is actually a transfer handler that takes into account all user requests and redirects requests that comply with the rules. For specific configuration parameters, see the official documentation: http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.2/index.html Configure the web. urlrewrite. the xml configuration file is placed in the WEB-INF directory, so that when urlrewritefilter is used, it will automatically read the relevant configuration under this directory, I configured a simple, the Code is as follows: [xhtml] <rule> <from>/zh_CN/NewsInfo/NEWS _ ([0-9] +) </from> <to>/zh_CN/NewsInfo/view. do? Method = view & amp; id = $1 </to> </rule> <outbound-rule> <from>/zh_CN/NewsInfo. do /? Method = view & amp; id = ([0-9] +) $ </from> <to>/zh_CN/NewsInfo/NEWS _ $1 </to> </outbound-rule> [xhtml] <rule> <from>/zh_CN/NewsInfo /NEWS _ ([0-9] +) </from> <to>/zh_CN/NewsInfo/view. do? Method = view & amp; id = $1 </to> </rule> <outbound-rule> <from>/zh_CN/NewsInfo. do /? Method = view & amp; id = ([0-9] +) $ </from> <to>/zh_CN/NewsInfo/NEWS _ $1 </to> </outbound-rule> the form rule in the rule node uses a regular expression by default. matched, when a user accesses the server, the URL will be compared with this configuration. If the rule is met, the URL will be redirected according to the configuration in the following to node. The default value is forward jump, for specific configurations, see the official website documentation. The outbound-rule node is the form of the page URL parsed by the server. The configuration is roughly the same as the above. For example, the form of a news link code written in JSP is as follows: [xhtml] <c: url var = "news_url" value = "/zh_CN/Press/view. do? Method = view & id =$ {cur. id} & msg = Press "/> <li> · <a href =" $ {news_url} "mce_href =" $ {news_url} "target =" _ blank "title =" $ {cur. titleSub} ">$ {cur. title} </a> </li> [xhtml] view plaincopy <c: url var = "news_url" value = "/zh_CN/Press/view. do? Method = view & id =$ {cur. id} & msg = Press "/> <li> · <a href =" $ {news_url} "mce_href =" $ {news_url} "target =" _ blank "title =" $ {cur. titleSub} ">$ {cur. title} </a> </li> after being parsed by the server, the result displayed on the page is: [xhtml] <li> · <a href = "/project name/zh_CN/NewsInfo/NEWS_9999" mce_href = "project name/zh_CN/NewsInfo/NEWS_9999" target = "_ blank" title = "$ {cur. titleSub} "> News Title </a> </li> [xhtml] view plaincopy <li> · <a href ="/project name/zh_CN/NewsInfo/NEWS_9999 "mce_href = "Project name/zh_CN/NewsInfo/NEWS_9999" target = "_ blank" title = "$ {cur. titleSub} "> News Title </a> </li> urlrewrite implements jsp url rewriting. When a user clicks this link, urlrewrite uses the rule configuration to redirect to the real access address, in this way, the link to be converted from the real address cannot be directly written in the tag, and must be written in the c: url or other variables to be parsed by the server so that the link can be re-displayed.

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.