今天项目过程当中发现不少超连接把参数所有暴露在浏览器地址栏,甚是担忧。幸亏,被我发现了一种实现技术,哈哈。。。。php
1.下载urlrewrite,官方下载地址:http://tuckey.org/urlrewrite/dist/urlrewritefilter-2.6.zip 有可能直接下载不了,你能够找个×××代理网站打开下载。html
如:http://www.cnproxy.com/webproxy.php web
下载获得urlrewritefilter-3.2.0.zip 解压后 找到lib下的urlrewrite-3.2.0.jar包拷贝到你的工程lib下,拷贝urlrewrite.xml到web_INF下。正则表达式
2.在web.xml中Filter的形式加载urlrewrite注明过滤的内容:浏览器
- <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>
3.修改urlrewrite.xmltomcat
- <?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>^/([a-z]+)$</from>
- <to type= "forward" >/world.jsp?id=$1</to>
- </rule>
- <rule>
- <from>^/world/(.*)$</from>
- <to>/world.jsp?tid=$1</to>
- </rule>
- <rule>
- <from>^/(.*).html$</from>
- <to>/test1/$1.jsp</to>
- </rule>
- <outbound-rule>
- <note>
- The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
- the url /rewrite-status will be rewritten to /test/status/.
- The above rule and this outbound-rule means that end users should never see the
- url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
- in your pages.
- </note>
- <from>/rewrite-status</from>
- <to>/test/status/</to>
- </outbound-rule>
- </urlrewrite>
rule是url重写规则,from是显示出来的地址,to是映射的实际地址,$1是重写参数,能够为多个,()里是匹配的正则表达式.
好了,在项目中新建world.jsp,启动tomcat,输入
http://localhost:8080/Uset/world/1
Uset是你的工程名
实际上访问的是http://localhost:8080/Uset/world.jsp?tid=1
这样就简单的实现了伪静态的效果
app