Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

java - Mask urls in JSP

Related to this question: URL characters replacement in JSP with UrlRewrite

I want to have masked URLs in this JSP Java EE web project. For example if I had this:

http://mysite.com/products.jsp?id=42&name=Programming_Book

I would like to turn that URL into something more User/Google friendly like:

http://mysite.com/product-Programming-Book

I've been fighting with UrlRewrite, forwarding and RequestDispatcher to accomplish what I want, but I'm kind of lost. I should probably have a filter for all http requests, re format them, and forward the page.

Can anyone give some directions? Tips?

Thanks a lot.

UPDATE: Servlets did it. Thanks Yuval for your orientation. I had been using UrlRewrite, as you can see at the first sentence of the question I also asked a question about that. But I couldn't manage to get UrlRewrite work the way I wanted. Servlets did the job.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could use a URLRewrite filter. It's like how mod_rewrite is for Apache's HTTP web server.

http://tuckey.org/urlrewrite/

"Redirect one url

<rule>
<from>^/some/old/page.html$</from>
<to type="redirect">/very/new/page.html</to>
</rule>

Tiny/Freindly url

<rule>
<from>^/zebra$</from>
<to type="redirect">/big/ugly/url/1,23,56,23132.html</to>
</rule>

"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...