JSP URL重写-urlrewrite
http://blog.csdn.net/mr_tank_/article/details/11892965
URL重写的目的不言而喻,首先引入urlrewrite-4.0.0.jar【或者其他版本】包,可以从官方下载。
1、web.xml【官方配置】
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <display-name></display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <!-- URL重写配置 -->
- <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>WARN</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>UrlRewriteFilter</filter-name>
- <url-pattern>/*</url-pattern><!-- 拦截所有URL -->
- </filter-mapping>
- </web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- URL重写配置 -->
<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>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern><!-- 拦截所有URL -->
</filter-mapping>
</web-app>
2、urlrewrite.xml
- <?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">
- <!--
- Configuration file for UrlRewriteFilter
- http://tuckey.org/urlrewrite/
- -->
- <urlrewrite>
- <!--自定义匹配-->
- <rule>
- <!-- <from>^/admin/(.*)(.*)</from> -->
- <from>admin/([0-9]+)/(.*).shtml/(.*)</from>
- <to>/admin_login.jsp?id=$1&name=$2&keyword=$3</to>
- </rule>
<?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">
<!--
Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/
-->
<urlrewrite>
<!--自定义匹配-->
<rule>
<!-- <from>^/admin/(.*)(.*)</from> -->
<from>admin/([0-9]+)/(.*).shtml/(.*)</from>
<to>/admin_login.jsp?id=$1&name=$2&keyword=$3</to>
</rule>
- <!-- 官方示例-->
- <rule>
- <note>
- The rule means that requests to /test/status/ will be redirected to /rewrite-status
- the url will be rewritten.
- </note>
- <from>/test/status/</from>
- <to type="redirect">%{context-path}/rewrite-status</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>
- <!--
- INSTALLATION
- in your web.xml add...
- <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>WARN</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>UrlRewriteFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- EXAMPLES
- Redirect one url
- <rule>
- <from>/some/old/page.html</from>
- <to type="redirect">/very/new/page.html</to>
- </rule>
- Redirect a directory
- <rule>
- <from>/some/olddir/(.*)</from>
- <to type="redirect">/very/newdir/$1</to>
- </rule>
- Clean a url
- <rule>
- <from>/products/([0-9]+)</from>
- <to>/products/index.jsp?product_id=$1</to>
- </rule>
- eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.
- Browser detection//浏览器检测
- <rule>
- <condition name="user-agent">Mozilla/[1-4]</condition>
- <from>/some/page.html</from>
- <to>/some/page-for-old-browsers.html</to>
- </rule>
- eg, will pass the request for /some/page.html on to /some/page-for-old-browsers.html only for older
- browsers whose user agent srtings match Mozilla/1, Mozilla/2, Mozilla/3 or Mozilla/4.
- Centralised browser detection
- <rule>
- <condition name="user-agent">Mozilla/[1-4]</condition>
- <set type="request" name="browser">moz</set>
- </rule>
- eg, all requests will be checked against the condition and if matched
- request.setAttribute("browser", "moz") will be called.
- -->
- </urlrewrite>
<!-- 官方示例-->
<rule>
<note>
The rule means that requests to /test/status/ will be redirected to /rewrite-status
the url will be rewritten.
</note>
<from>/test/status/</from>
<to type="redirect">%{context-path}/rewrite-status</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>
<!--
INSTALLATION
in your web.xml add...
<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>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
EXAMPLES
Redirect one url
<rule>
<from>/some/old/page.html</from>
<to type="redirect">/very/new/page.html</to>
</rule>
Redirect a directory
<rule>
<from>/some/olddir/(.*)</from>
<to type="redirect">/very/newdir/$1</to>
</rule>
Clean a url
<rule>
<from>/products/([0-9]+)</from>
<to>/products/index.jsp?product_id=$1</to>
</rule>
eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.
Browser detection//浏览器检测
<rule>
<condition name="user-agent">Mozilla/[1-4]</condition>
<from>/some/page.html</from>
<to>/some/page-for-old-browsers.html</to>
</rule>
eg, will pass the request for /some/page.html on to /some/page-for-old-browsers.html only for older
browsers whose user agent srtings match Mozilla/1, Mozilla/2, Mozilla/3 or Mozilla/4.
Centralised browser detection
<rule>
<condition name="user-agent">Mozilla/[1-4]</condition>
<set type="request" name="browser">moz</set>
</rule>
eg, all requests will be checked against the condition and if matched
request.setAttribute("browser", "moz") will be called.
-->
</urlrewrite>
3、项目结构:
4、admin_login.jsp页面代码:
- <body>
- Admin Login Page.
- <br>
- <%=request.getParameter("id")%><br>
- <%=request.getParameter("name")%><br>
- <%=request.getParameter("keyword")%>
- </body>
<body>
Admin Login Page.
<br>
<%=request.getParameter("id")%><br>
<%=request.getParameter("name")%><br>
<%=request.getParameter("keyword")%>
</body>
测试结果:
http://123.125.115.53/view/1002788.html?fromTaglist
JSP URL重写-urlrewrite相关推荐
- tp3 普通模式url模式_[tp3.2.1]开启URL(重写模式),省略URL中的index.php
重写模式(省略url中的index.php) 在apache配置文件httpd.conf中,查找 1.mod_rewrite.so, 启动此模块 2.AllowOverride , 值= All 3. ...
- UrlRewrite(URL重写)--ASP.NET中的实现
概述 今天看了下URL重写的实现,主要看的是MS 的URL Rewrite. URL重写的优点有:更友好的URL,支持老版本的URL URL重写的缺点有:最主要的缺点是性能低下,因为如果要支持无后缀的 ...
- UrlRewrite(Url重写技术)
ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置------转载 ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置 核心提示:大家一定经常在网络上看到很多网站的 ...
- url重写(urlrewrite)的一些系统变量
学php也有3年了,一直对url重写不是很了解,本学用到的话都是百度一下,再复制作简单修改,一些变量的参数都不太了解什么意思,难得今天有时间,做个笔记吧! 1)可用的一些系统变量,在重写条件和重写规则 ...
- java 重写url_网站URL重写(Java UrlRewrite 的使用)
现在大部分的网站和商城都会使用到URL重写,接触到这个,也是因为正在做的电子商务商城.URL重写,是将原有的URL采用另一种规则来显示,使得用户方便访问同时也屏蔽一些信息. 在此说下它的好处,在开发过 ...
- windows2008(64位)下iis7.5中的url伪静态化重写(urlrewrite)
以前在windows2003里,使用的是iis6.0,那时常使用的URL重写组件是iisrewrite,当服务器升级到windows2008R2时,IIS成了64位的7.5,结果iisreite组件是 ...
- ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置
核心提示:大家一定经常在网络上看到很多网站的地址后缀都是用XX.HTML或者XX.ASPX等类似静态文件的标示来操作的吧,那么大家有怀疑过他真的是一个一个的静态生成的文件么,静态文件的生成的优缺有好有 ...
- java urlrewriter_java url重写技术(UrlReWriter)
现在url重写技术用的越来越广泛了,很高兴今天和各位网友分享一下: 首先我们要从网上下一个UrlReWriter jar包 现在地址进不了,我这里有一个3.0版本的,文章底有下载地址,大家可以去下载 ...
- 《转》java URL重写
文章来源:http://www.it300.com/article-5319.html 现在url重写技术用的越来越广泛了,很高兴今天和各位网友分享一下: 首先我们要从网上下一个UrlReWrite ...
最新文章
- GraphSAGE: GCN落地必读论文
- 批处理(定时器) ssm spring-task
- 解析Objective-C中多态、动态类型和动态绑定
- LInux 安全测试 2
- Python—— *与** 参数说明
- javafx 浏览器_浏览器中的JavaFX
- 农历php,php阳历转农历优化版
- springboot和vue data数据为空_常见数据结构的 Python 实现(建议收藏)
- Flutter — 实现验证码倒计时功能
- C++ 派生类和virtual
- python 03day上--网络基础及dos命令
- linux自学第二天
- 参考 雷霄骅https://blog.csdn.net/leixiaohua1020/article/list/28
- 密码学【java】初探究加密方式之非对称加密
- 飞利浦e570有JAVA吗_飞利浦E570不仅仅是手机还是一款可通话的移动电源
- 减少参数!SPViT:视觉Transformer剪枝新方法
- 人工智能与大数据行业的兴起,主要产生了哪些新的职位?
- C语言和JAVA的关联
- 【59元 第二件1元】SIMEITOL/姿美堂玛卡片 蓝玛咖片MACA 60片
- GO--redis redigo hel 删除多个参数的传值方法
热门文章
- 【数据结构与算法】之深入解析“正则表达式匹配”的求解思路与算法示例
- 【数据结构与算法】之深入解析如何确定单链表有环并求环的入口和长度
- Python中lambda表达式的优缺点及使用场景
- PAT (Basic Level) Practice (中文)1006 换个格式输出整数 (15 分)
- python 读取word 题库_Python-docx 读取word.docx内容
- socket连接时间太长受什么原因影响?_真全粮多功能酿酒设备-酿酒发酵前期为什么要通风处理?...
- java ssm使用存储过程_java调用oracle存储过程(ssm)
- 推箱子java下载_Java实现简单推箱子游戏
- 新疆大学(新大)OJ xju 1010: 四个年级 C++ STL map 将4层循环优化成2层循环可解
- Xcode 不用签名编译程序