废话不说,直接搞起:
1:导入urlrewritefilter-2.6(较稳定)包到工程web — WEB-INF下的lib下面,直接copy进去就OK了,下载地址:http://download.csdn.net/detail/andylau3317/3947327
2:在web.xml里面的配置相关信息:
<!-- UrlRewriteFilter伪静态 -->
<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>commons</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意init-param中一定要写,我试过不写,但是没什么效果,而且value值为commons 还有几个参数这个大家自己研究
3:将上面下载地址中的urlrewrite.xml复制到WEB-INF下面,修改其中的内容,如下:
<urlrewrite>
<rule>
<note></note>
<from>^/index_login.html</from>
<to type="forward">/index_login.jsp</to>
</rule>
</urlrewrite>
注意将type设为forward
4:测试:
真实的路径为:
http://127.0.0.1:7878/ydxh/index_login.jsp
在url地址拦中,只需要输入下面的地址,实际上是转到上面的url
http://127.0.0.1:7878/ydxh/index_login.html