今天項目過程當中發現不少超連接把參數所有暴露在瀏覽器地址欄,甚是擔憂。幸虧,被我發現了一種實現技術,哈哈。。。。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