1、Urlrewritefilter说明及优点html
Urlrewritefilter,经过java的Filter过滤器对URL进行重写,用户获得的所有都是通过处理后的URL地址,本质上经过伪地址进行页面跳转,隐藏真实地址,达到掩人耳目的目的,哈哈。java
有如下优点:
1:提升安全性,能够有效的避免一些参数名、ID等彻底暴露在用户面前,若是用户随便乱输的话,不符合规则的话直接会返回个404或错误页面,这比直接返回500或一大堆服务器错误信息要好的多
2:美化URL,去除了那些好比*.do,*.action之类的后缀名、长长的参数串等,能够本身组织精简更能反映访问模块内容的URL web
3:更有利于搜索引擎的收入,经过对URL的一些优化,可使搜索引擎更好的识别与收录网站的信息正则表达式
2、网络资源安全
一、下载地址 官网:http://tuckey.org/urlrewrite/ google code :https://code.google.com/p/urlrewritefilter/服务器
二、文档使用说明:http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html网络
3、使用步骤app
一、在web.xml中加入如下代码 jsp
<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> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>
二、在urlrewrite.xml配置文件中进行地址映射规则,使用正则表达式svn
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd"> <urlrewrite> <rule> <from>^/newsInfo-list-([0-9]+).shtml$</from> <to>/NewsInfo.do?method=list&mod_id=$1</to> </rule> <outbound-rule> <from>/NewsInfo.do\?method=list&mod_id=([0-9]+)$</from> <to>/newsInfo-list-$1.shtml</to> </outbound-rule> </urlrewrite>
三、JSP中使用以下地址
<c:url var="url_1001001000" value="/NewsInfo.do?method=list&mod_id=1001001000" /> <li><a href="${url_1001001000}">测试地址</a></li>
官网文档中提供以下使用方式:
Using the example above JSP's with the code <a href="<%= response.encodeURL("/world.jsp?country=usa&city=nyc") %>">nyc</a> will output <a href="/world/usa/nyc">nyc</a> Or JSTL <a href="<c:url value="/world.jsp?country=${country}&city=${city}" />">nyc</a> will output <a href="/world/usa/nyc">nyc</a> Note, If you are using JSTL (ie, <c:url) this will work also.
四、基本原理
jsp页面地址--> 服务器filter过滤 --> 调用urlrewrite.xml映射规则 --> 服务器响应 --> 转换成伪地址
五、小结:Urlrewritefilter简单易学易用,是Java Web开发中地址隐藏的不二选择。