如何在J2EE中进行动态URL重写 [英] How to do dynamic URL Rewriting in J2EE

查看:117
本文介绍了如何在J2EE中进行动态URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回到我的ASP.NET时代,我使用 URLRewriter.NET 来进行动态URL重写。基本上,它是一个HTTPModule,它拦截页面请求并根据您定义的规则重写URL,非常类似于MOD_REWRITE。但是,它还允许您定义自定义变换,这是一个具有单一方法的类,可以即时为您进行URL转换。您可以使用此方法访问数据库,访问Application []集合,几乎可以做任何您想要的事情。

Back in my ASP.NET days, I used URLRewriter.NET to do dynamic URL Rewrites. Basically, it's an HTTPModule that intercepts page requests and rewrites the URLs according to rules that you define, very similar to MOD_REWRITE. However, it also lets you define a "Custom Transform," a class with a single method that does URL translations for you on-the-fly. You can have this method hit the DB, access the Application[] collection, pretty much do anything your heart desires.

J2EE世界中是否有相应的内容?我希望能够动态地重写URL并将此重写委托给某些Java代码。我不想只设置一个静态重写列表。同样,它需要进行实际的URL屏蔽,而不是3XX重定向。

Is there any equivalent to this in the J2EE world? I want to be able to rewrite URLs dynamically and delegate this rewriting to some Java code. I do NOT want to just set up a list of static rewrites. Likewise, it needs to do actual URL masking, and NOT 3XX redirects.

如果没有这样做的话,我将如何自行构建此功能?

If there isn't anything out there that does this, how would I go about building this functionality myself?

推荐答案

您是否调查了 Servlet过滤器?我没有尝试直接修改URL,我相信这些参数会被预先解析为请求对象,但我们会广泛使用这些过滤器来解析URL并将路径信息放入数据库以供其他Servlet和JSP使用。

Have you investigated Servlet Filters? I have not attempted to modify the URL directly and I believe the parameters would be pre-parsed into the request object, but we use the filters extensively for parsing URLs and putting path info into the DB for other Servlet and JSP use.

您可以非常轻松地将请求对象包装到目标Servlet中。

You could very easily wrap the request object as it chains through to the target Servlets.

这篇关于如何在J2EE中进行动态URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆