1.在web.xml中配置一个过滤器
<filter>
<filter-name>testfilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>//此包需要下载
</filter>
<filter-mapping>
<filter-name>testfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.新建一个urlrewrite.xml文件 与web.xml放在一起 配置如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
"http://tuckey.org/res/dtds/urlrewrite2.6.dtd">
<!--
Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/
-->
<urlrewrite>
<rule>
<from>index.html</from> //随便命名的
<to >/index.jsp</to> //源文件
</rule>
<rule>
<from>(/d*).php</from> //地址栏中显示的 (/d*) 表示所有数字
<to >/jsp1.jsp?id=$1</to> //源文件 传参数
</rule>
</urlrewrite>
3.测试页面
<html>
<head>
<title>
index
</title>
</head>
<body bgcolor="#ffffff">
<h1>
JBuilder Generated JSP
</h1>
<a href="jsp1.html">asdfasfasd</a>
<%
for(int i=10;i<100;i++)
{
out.print("<a href="+i+".php>");
out.print(i+i+i);
out.print("</a><br>");
}
%>
</body>
</html>
jsp1.jsp页面
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<h1>
<a href="index.html">index</a>
<%=request.getParameter("id") %>
</h1>
</body>
</html>