implement url-rewrite in j2ee application

本文介绍如何通过URL重写技术改善J2EE应用程序的URL结构,使其更简洁美观且搜索引擎友好。通过使用UrlRewriteFilter实现从传统URL到更简洁格式的转换。

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:

  1. visit web site http://tuckey.org/urlrewrite/   , and downoad the latest version.
  2. add the lib urlrewrite-xxx.jar to ur app web-inf/lib folder.
  3. add the following to ur web-inf/web.xml:
  4. <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>
  5. 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 :
  6. <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.
  7. 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.

【事件触发一致性】研究多智能体网络如何通过分布式事件驱动控制实现有限时间内的共识(Matlab代码实现)内容概要:本文围绕多智能体网络中的事件触发一致性问题,研究如何通过分布式事件驱动控制实现有限时间内的共识,并提供了相应的Matlab代码实现方案。文中探讨了事件触发机制在降低通信负担、提升系统效率方面的优势,重点分析了多智能体系统在有限时间收敛的一致性控制策略,涉及系统模型构建、触发条件设计、稳定性与收敛性分析等核心技术环节。此外,文档还展示了该技术在航空航天、电力系统、机器人协同、无人机编队等多个前沿领域的潜在应用,体现了其跨学科的研究价值和工程实用性。; 适合人群:具备一定控制理论基础和Matlab编程能力的研究生、科研人员及从事自动化、智能系统、多智能体协同控制等相关领域的工程技术人员。; 使用场景及目标:①用于理解和实现多智能体系统在有限时间内达成一致的分布式控制方法;②为事件触发控制、分布式优化、协同控制等课题提供算法设计与仿真验证的技术参考;③支撑科研项目开发、学术论文复现及工程原型系统搭建; 阅读建议:建议结合文中提供的Matlab代码进行实践操作,重点关注事件触发条件的设计逻辑与系统收敛性证明之间的关系,同时可延伸至其他应用场景进行二次开发与性能优化。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值