url地址静态化
来源:互联网 发布:exo知乎 编辑:程序博客网 时间:2024/05/21 06:53
urlrewrite可以将动态的URL进行伪静态,比如把
xxxx.jsp?id=1转为http://xxxx/xxx/1
这里发现一个好工具:tuckey urlrewrite,使用方法如下:
1 下载urlrewrite,官方下载地址:http://tuckey.org/urlrewrite/dist/urlrewritefilter-2.6.zip
2 放到项目的LIB包中
3 建立urlrewrite.xml文件,放到WEB-INF
目录下,编写如下:
<?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>
<?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是重写参数,可以为多个,()里是匹配的正则表达式.
比如:
<rule>
<from>/(.*)/login.htm</from>
<to type="forward">/yui/login.htm?name=$1</to>
</rule>
http://localhost:8080/app/abc/login.htm其实际请求的url为http://localhost:8080/app/yui/login.htm?name=abc
4 配置WEB.XML
<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>
<listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/urlrewrite.xml </param-value>
</context-param>
xxxx.jsp?id=1转为http://xxxx/xxx/1
这里发现一个好工具:tuckey urlrewrite,使用方法如下:
1 下载urlrewrite,官方下载地址:http://tuckey.org/urlrewrite/dist/urlrewritefilter-2.6.zip
2 放到项目的LIB包中
3 建立urlrewrite.xml文件,放到WEB-INF
目录下,编写如下:
<?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>
<?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是重写参数,可以为多个,()里是匹配的正则表达式.
比如:
<rule>
<from>/(.*)/login.htm</from>
<to type="forward">/yui/login.htm?name=$1</to>
</rule>
http://localhost:8080/app/abc/login.htm其实际请求的url为http://localhost:8080/app/yui/login.htm?name=abc
4 配置WEB.XML
<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>
<listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/urlrewrite.xml </param-value>
</context-param>
- url地址静态化
- URLRewrite 实现URL地址伪静态化
- UrlRewriteFilter实现URL地址伪静态化
- URLRewrite实现URL地址伪静态化
- URLRewrite实现url地址伪静态化
- URLRewirte实现url地址伪静态化
- URLRewrite 实现URL地址伪静态化
- url rewrite 实现url地址的伪静态化
- JSP使用URLRewirte实现url地址伪静态化(转)
- JSP使用URLRewirte实现url地址伪静态化
- 1使用URLRewrite实现url地址伪静态化(转载)
- JSP使用URLRewirte实现url地址伪静态化
- jsp使用URLRewrite实现url地址伪静态化
- JSP页面静态化总结之一使用URLRewrite实现url地址伪静态化
- JSP页面静态化总结之一使用URLRewrite实现url地址伪静态化
- JSP页面静态化总结之一使用URLRewrite实现url地址伪静态化
- 使用伪Url地址(伪静态)
- We7如何设置伪静态URL地址
- iframe自適應高度
- NewsStand书架效果(精选)
- C++中禁止类被派生的方法
- android&&ScaleType
- pragma详解
- url地址静态化
- 如何调用MFC dll 来显示其中的对话框
- (2011.12.01)未有答案:接下来如何写博客呢?
- Android画图之Matrix(一)
- 【编程语言】java--集合
- Ubuntu系统启动过程详解
- 又发现amfext的几处内存泄漏的bug
- VS2008 代码对齐
- 人生如棋