JSP中的掩码URL [英] Mask urls in JSP

查看:143
本文介绍了JSP中的掩码URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与此问题相关:
JSP中的URL字符替换UrlRewrite

我想在此JSP Java EE Web项目中使用屏蔽URL。
例如,如果我有这个:

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

我想把这个网址变成更像User / Google友好的东西: / p>

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

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

我一直在与UrlRewrite,转发和RequestDispatcher斗争,以实现我想要的,但我有点迷茫。我应该对所有http请求都有一个过滤器,重新格式化它们,然后转发页面。

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?

非常感谢。

UPDATE: Servlets做到了。感谢Yuval的指导。
我一直在使用UrlRewrite,正如你在问题的第一句中看到的那样我也问了一个问题。但我无法按照我想要的方式让UrlRewrite工作。 Servlets完成了这项工作。

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.

推荐答案

自从我讨论JSP以来已经有一段时间了,但如果内存服务可以添加URL模式到您的web.xml(或其中一个XML配置文件)并让servlet引擎自动将请求路由到您选择的参数的有效URL。如果您愿意,我可以查看详细信息。

It's been a while since I mucked about with JSPs, but if memory serves you can add URL patterns to your web.xml (or one of those XML config files) and have the servlet engine automatically route the request to a valid URL with your choice of paramters. I can look up the details if you like.

在您的情况下,地图 http://mysite.com/product-Programming-Book 到URL
http://mysite.com/products.jsp?id=42&name=Programming_Book ,用户不再看到真正的URL。此外,您可以在应用程序中使用此用户友好的URL作为该页面的逻辑名称。

In your case, map http://mysite.com/product-Programming-Book to the URL http://mysite.com/products.jsp?id=42&name=Programming_Book and the user no longer sees the real URL. Also, you can use this more user-friendly URL within your application, as a logical name for that page.

Yuval = 8 - )

Yuval =8-)

这篇关于JSP中的掩码URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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