利用URLrewrite实现伪静态地址输出

今天项目过程当中发现不少超连接把参数所有暴露在浏览器地址栏,甚是担忧。幸亏,被我发现了一种实现技术,哈哈。。。。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注明过滤的内容:浏览器

  
  
  
  
  1. <filter> 
  2.         <filter-name>UrlRewriteFilter</filter-name> 
  3.         <filter-class> 
  4.             org.tuckey.web.filters.urlrewrite.UrlRewriteFilter  
  5.         </filter-class> 
  6.     </filter> 
  7.     <filter-mapping> 
  8.         <filter-name>UrlRewriteFilter</filter-name> 
  9.         <url-pattern>/*</url-pattern> 
  10.     </filter-mapping> 

3.修改urlrewrite.xmltomcat

  
  
  
  
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"   
  3. "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">   
  4.  
  5. <!--   
  6.  
  7. Configuration file for UrlRewriteFilter   
  8. http://tuckey.org/urlrewrite/   
  9.  
  10. -->   
  11. <urlrewrite>   
  12.     <rule>   
  13.         <from>^/([a-z]+)$</from>   
  14.         <to type"forward" >/world.jsp?id=$1</to>   
  15.     </rule>   
  16.     <rule> 
  17.         <from>^/world/(.*)$</from> 
  18.         <to>/world.jsp?tid=$1</to> 
  19.     </rule> 
  20.     <rule> 
  21.         <from>^/(.*).html$</from> 
  22.         <to>/test1/$1.jsp</to> 
  23.     </rule> 
  24.       
  25.     <outbound-rule>   
  26.         <note>   
  27.         The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)   
  28.         the url /rewrite-status will be rewritten to /test/status/.   
  29.           
  30.         The above rule and this outbound-rule means that end users should never see the   
  31.         url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks   
  32.         in your pages.   
  33.         </note>   
  34.         <from>/rewrite-status</from>   
  35.         <to>/test/status/</to>   
  36.     </outbound-rule> 
  37. </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

相关文章
相关标签/搜索