url伪实现

url伪静态实现

1 下载urlrewrite包,地址:http://code.google.com/p/urlrewritefilter/downloads/list

2 解压

3将urlrewrite-4.0.0.jar文件引入到项目中,并将urlrewrite.xml添加到WEB-INF目录下

url伪实现

4 修改web.xml配置

<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>

5 配置urlrewrite.xml文件

<rule>
        <note>
            The rule means that requests to /test/status/ will be redirected to /rewrite-status
            the url will be rewritten.
        </note>
        <from>/(.*).html</from>
        <to>/index.jsp?id=$1</to>
    </rule>

6 index.jsp代码

<body>
		<%
		    String id = request.getParameter("id");
		    out.println("<h3> the value is  : " + id + " </h3> ");
		%>
	</body>
7 访问地址:http://ip:port/path/test.html,自动跳转到/index.jsp?id=test,显示如下 url伪实现



你可能感兴趣的:(urlrewrite,url伪实现)