in many j2ee applications, especially which developed by light-weight framework,such as struts, we can easily see the url pattern as follows :
写道
http://localhost:8080/app/module/action.do?id=x&
In contrast, the url pattern used by ruby on rails applications are totally different:
写道
http://localhost:3000/app/module/action/id
Compare the two url patterns, I think most people may choose the latter, for its simplicity and beauty. Apparently, the second one reduce the usage of symbol ? and &. beside that , the second one also is 'search engine friendly'
-- it has a higher chance to be searched by searching engine like google. So , hao can we get way from the ugly url pattern in j2ee applications. the answer is : url-rewrite.
url-rewrite is a technology that substitute dynamic pages for static pages. for example, the page /user/list.do?id=123 can be visited by url /url/list/123 if we have configured related url-rewrite rule.
there are two ways to implement url-rewrite in j2ee application:
- using proxy http server. Apache HTTP Server 2.x and mod_proxy provide the url-rewrite function.
- except that, using the third side lib is also a good choice. such as UrlRewriteFilter.
in this topic, i will introduce the second way.(the other would be introduced serval days latter.)
the stepes to use UrlRewriteFilter in ur app as follows:
- visit web site http://tuckey.org/urlrewrite/
, and downoad the latest version.
- add the lib urlrewrite-xxx.jar to ur app web-inf/lib folder.
- add the following to ur web-inf/web.xml:
-
<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>
</filter-mapping>
- create the file urlrewrite.xml
in ur app web-inf/ folder. default, urlRewriteFilter will use the file to apply rewriter rule. add the following content to urlrewrite.xml :
-
<urlrewrite>
<rule>
<from>/([a-zA-Z]+)/([a-zA-Z]+)/([0-9]+)</from>
<to>/$1/$2.do?id=$3</to>
</rule>
</urlrewrite>
the rule displayed above means that any url like /user/list/123 will be rewrited to /user/list.do?id=123.
- after all things above were done rightly. now, we can input the /user/list/123 in browser and the url will be correctly rewrited and display related content.
urlrewrite.xml introduction
urlrewrite.xml must have a root element called <urlrewrite></urlrewrite>
, and at least contains one "rule"
element.
'rule'
element is the core of xml. a 'rule' element stand for a url-rewrite rule. 'rule' element must contains a 'to'
and 'from'
element, and for some advanced application, also could contains the optional elements like 'condition' and 'set'. the official site describe the process flow as follows:
When a "rule" is processed against an incoming request, all the "condition" elements must be met, then the "from" will be applied to the request URL and the final URL generated by applying the "to" to the "from" pattern. So long as the rule has matched then the "set" will be run.
the value specified in 'to' and 'from' elements must be relative to the request context, and can be a regular expression in the perl5 style.
分享到:
相关推荐
the implement and application of MySQL database in VC++, quite useful for those who want to use MySQL database in VC++ programs.
Using Linux to Implement 8- and 16- Bit Device Networking Solutions.pdf
SAP 方法论 Run SAP Methodology How to Implement End-to-End Solution Operations
Using Linux to Implement 8- and 16- Bit Device Networking Solutions
前端大厂最新面试题-implement-map-using-reduce.docx
前端大厂最新面试题-implement-queue-using-stack.docx
detection of heart disease, which is a leading cause of morbidity and mortality in western countries. It is estimated that more than 100 million ECGs are recorded annually in Western Europe. In view ...
Developers and software engineers interested in learning an end-to-end approach to application development using Microsoft technologies. Table of Contents Chapter 1: Designing a Modern Real-World Web...
实施PPO处罚。你会发现,无论是加速还是基线都没有实现PPO惩罚。尽管PPO惩罚结果不如PPO剪辑,但该算法作为一个好的基线是有意义的。 在Atari域上实现PPO算法(如果你运行程序,你会发现程序与Atari域不匹配。...
6.4.1-packet-tracer---implement-etherchannel.pka
1.6.1 Packet Tracer - Implement a Small Network Cisco Packet Tracer 思科模拟器 正确答案文件 可直接上交正确答案文件 本答案版权归mewhaku所有,严禁再次转载!!! Copyright @mewhaku 2022 All Rights ...
how-to-implement-a-DB-like-sqlite ##Description 在这个项目中我们会学习SQLite源码并仿制其做成一个完整的数据库. 整个过程中我们会对SQLite进行多次demo, 不断的加入新功能, 直到其成为一个安全, 快速, 功能较为...
Coordination Multi Point Transmission Reception for 2 Cells and One UE
RSA-Montgomery-Algorithm-Hardware-implement-master.zip
Complete with code examples that can be altered and applied to your application and careful explanations, this book will guide you through your first interaction with object-oriented programming ...
7.4.1 Packet Tracer - Implement DHCPv4 Cisco Packet Tracer 思科模拟器 正确答案文件 由于程序问题无法保存激活DHCP端口配置 另加满分步骤截图 可直接上交正确答案文件 本答案版权归mewhaku所有,严禁再次...
inter- and intra-application messaging a breeze. In this chapter, we look into Enterprise Integration from a general standpoint. We discuss the problem space that Spring Integration Framework is ...
DS-5000 数字存储示波器 用户手册
In addition to the software, it features bonus projects, application notes, and video tutorials. A reader forum, monitored by the author, gives you the opportunity for questions and information ...