Java uses URLRewrite to implement pseudo-static web pages (servlet filters) and urlrewriteservlet

Source: Internet
Author: User

Java uses URLRewrite to implement pseudo-static web pages (servlet filters) and urlrewriteservlet
Step 1: import the package urlrewrite 3.2.0.jar: (click to download)
Step 2: configure the filter in the web. xml file. The Code is as follows:

<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> </filter-mapping>

Step 3: Create the urlrewrite. xml file under the WEB-INF with the following code:
<? 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>/userinf-(\ w * mongo.html </from> <to type = "forward">/userinf. jsp? Username = $1 </to> </rule> </urlrewrite>
Note: As long as the access path is.../userinf-(\ w * ).html, it will be parsed into userinf. jsp? Below username = $1 is a test jsp page,
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; String user = request. getParameter ("username"); %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> NewJava. util. Date () + "</br>"); out. println ("username:" + user); %> </body>
Running example: ================================== END ========== ======================================

Related Article

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.