How to do dynamic URL Rewriting in J2EE

坚强是说给别人听的谎言 提交于 2019-12-04 12:47:43

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.

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

skaffman

How about these:

http://ocpsoft.com/prettyfaces/

PrettyFaces is an OpenSource Filter-based Servlets extension with enhanced support for JavaServer Faces – JSF 1.1, 1.2 and 2.0 – enabling creation of bookmark-able, pretty URLs. PrettyFaces solves the “RESTful URL” problem elegantly, including features such as: page-load actions, seamless integration with faces navigation, dynamic view-id assignment, managed parameter parsing, and configuration-free compatibility with other web frameworks.

http://ocpsoft.com/rewrite/

Rewrite is an OpenSource Filter-based Servlets extension for Java – enabling creation of bookmark-able, pretty URLs. Rewrite solves the “RESTful URL” problem elegantly, including features such as: page-load actions, managed parameter parsing, seamless integration with CDI, Spring, and configuration-free compatibility with other web frameworks.

http://tuckey.org/urlrewrite/

Based on the popular and very useful mod_rewrite for apache, UrlRewriteFilter is a Java Web Filter for any J2EE compliant web application server (such as Resin, Orion or Tomcat), which allows you to rewrite URLs before they get to your code. It is a very powerful tool just like Apache's mod_rewrite.

The other option is write your won Servlet . Now write some URL manipulation code using the request object and URL found and call the intended page action or Servlet again.

Eg.

you should call Servlet using URL

domain/urlServlet/param1/param2/...

And your Servlet will translate it to

domain/requestedPage?p1=param1&p2=param2...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!