首先要去下载一个urlrewritefilter-2.6.zip,然后把它解压到WEB-INF下,然后配置一下web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
然后再随便建立几个jsp页面,如:MyJsp.jsp
<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<%
String a = request.getParameter("id");
%>
<%
if(a.equals("123"))
{
out.println("ok!");
}
else
{
out.println("okok!");
}
%>
</body>
</html>
接着在urlrewrite.xml里配置一下路径
<?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>
<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>
<rule>
<from>/test/([0-9]+)</from>
<to>/index.jsp?id=$1</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.
-->
</urlrewrite>
启动服务器,然后输入http://localhost:8080/test/123 ,那么就可以显示了,而实际上读取的路径是http://localhost:8080/MyJsp.jsp?id=123
分享到:
相关推荐
jsp 动态转静态 URL重写 jsp 动态转静态 URL重写 jsp 动态转静态 URL重写 jsp 动态转静态 URL重写
urlrewritefilter的资源包,包含总结的配置说明文件,属性文件和相关jar包等,版本是2.6.
jsp的一个url重写 达内郑州中心老师的分享 好东西哦~
伪静态URL重写实际就是以静态地址(如:http://127.0.0.1:8080/pro/index.html)访问地态网页的方法(如:http://127.0.0.1:8080/pro/index.jsp)。 这个项目里有两个示例 输入...
当我们的要访问的不是html时,我们可以使用url重写实现url欺骗。和封杀某一类用户
伪静态URL重写实际就是以静态地址(如:http://127.0.0.1:8080/pro/index.html)访问地态网页的方法(如:http://127.0.0.1:8080/pro/index.jsp)。 伪静态URL重写是通过微软公司封装好了的一个URL重写组件...
下载后解压,为两个解压文件和一个说明文档。详细请看说明文档。。。。
Asp.Net 做的水印图片 和 URL地址重写,如果后缀名是.aspx将它在地址栏改变为其他的后缀名显示~~如*.jsp,*.php 等!!
URL重写 一、实验目的 1.掌握Myeclipse的使用。 2.掌握URL重写的基本思想并实现的使用。 二、实验内容 三、实验步骤
get提交中文乱码 地址重写中文乱码 jsp url中文乱码四种解决方式
一个高度可配置的URL重写工具,适用于Java EE 6+和Servlet 2.5+应用程序,支持与以下组件的集成: CDI 弹簧DI JodaTime配置 Tuckey.org URLRewriteFilter配置 JavaServer Faces(JSF) JavaServer页面(JSP) ...
在其它动态语言如asp、JSP、PHP中要实现URL地址重写需要借助于其它的手段(有一些现成可用的用于实现URL地址重写的dll库),使用这些第三方手段时需要对IIS做些配置,如果网站放置在购买的虚拟主机上可能就不能够...
UrlRewriter Java v2.0 RC1 是一个用于Java Web应用程序的URL重写工具的早期候选版本。URL重写是一个常见的技术,用于改变Web应用程序的URL结构,使其更加符合SEO(搜索引擎优化)的要求,或者使其更易于用户记忆和...
隐藏表单案例-index.jsp 把id写进Hidden表单里,用户看 不见,但是只要表单一提交, 这个参数值就可以提交给a.jsp 隐藏表单 VS URL重写 同重写URL技术相比,隐藏表单技术是利用表单来传递会话信息,而URL重写技术是...
4.Url重写 问号传参 LoginServlet?username=zhangsan&pwd=123 String name = request.getParameter("username"); String pwd =request.getPareameter("pwd"); 内部跳转: LoginServlet request.getRequestDispatcher...
urlrewrite 只支持单个配置文件,默认的配置文件为:/WEB-INF/urlrewrite.xml 现在对urlrewrite-3.2的源码进行了修改,使它能够支持多文件和通配符的形式加载自定义配置文件,即可以进行如下的配置: <param-name>...
JSP100选择题 适合考前练习 1 J2EE 中,()类的()方法用于创建对话。(选择一项) ...在禁用Cookie时可以使用URL重写技术跟踪会话 D.隐藏表单域将字段添加到HTML表单并在客户端浏览器中显示 …………
4.3.4 session对象与URL重写 116 4.3.5 记数器 118 4.4 OUT对象 119 4.5 APPLICATION对象 121 4.5.1 applicaton对象的常用方法 121 4.5.2 用applicaton对象制作留言板 122 第5章 JSP与JAVABEAN 126 5.1 编写和使用...
java和jsp很好的重定向和URL重写组件 <br>【JAVA/JSP/DB高手】QQ群:17398054 【Linux高手群】QQ群:26976792 地址:www.web-java.com<br>百度Blog:http://hi.baidu.com/zjqwll
使用模糊查询得到用户列表,超链接到修改用户信息页面时,使用URL重写,因为刚学到JavaBean,写这个的时候也用到了。。。请大家下载后记得评分。。那样就不扣你们的资源分了。。适合像我一样的初学者。。。使用工具:...