Java implements Web page pseudo-static using Urlrewrite (servlet filter)

Source: Internet
Author: User

Step 1: Introducing PackagesUrlrewrite 3.2.0.jar: (Click I download)
Step 2: The filter filter is configured in the Web. xml file, the code is as follows
< filter >       < filter-name  > </ 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: Web-inf Create a new Urlrewrite.xml file 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  > </ 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?username=$1 the following 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" > <html> <  > &NBSP;&NBSP;&NBSP;  < href <%=   %>   " > &NBSP;&NBSP;&NBSP;  < > <%=   user  %   personal information </ title  > < body > <% out.println ("Now Time is:" + new java.util.Date () +"</br>" ); out.println ("user name:"+user); %> </body > </html>
Run Example: ==============================end==================================

Java implements Web page pseudo-static using Urlrewrite (servlet filter)

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.