Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 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 Answer

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>

"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...