简体   繁体   English

Java Servlet API:从URL删除GET参数

[英]Java Servlet API: Remove GET parameters from URL

Is there anyway to remove the GET parameters from the request URL? 无论如何,是否有从请求URL中删除GET参数的信息? Such that when the response arrives to the client, the window's location will be a URL clean from GET parameters. 这样,当响应到达客户端时,窗口的位置将是从GET参数清除的URL。 Is there anyway to do this without doing any redirects and that the parameters passed will be accessible on the server? 无论如何,是否可以执行此操作而不进行任何重定向,并且可以在服务器上访问传递的参数?

Thanks! 谢谢!

Purpose: 目的:
It is to shorten the URL. 这是为了缩短URL。 Currently in my site, links will have a handler that will convert GET parameters into hash parameters. 当前在我的站点中,链接将具有一个将GET参数转换为哈希参数的处理程序。 After this, a location hash change listener will perform an AJAX request (with the location hash parameters) to reload certain parts of the document. 此后,位置哈希更改侦听器将执行AJAX请求(带有位置哈希参数)以重新加载文档的某些部分。 When trying to open the links in new windows/tabs, I plan to "clean" the URL parameters and put it into the location hash, delimited by some string. 当尝试在新的窗口/选项卡中打开链接时,我计划“清理” URL参数并将其放入位置哈希中,该哈希由一些字符串分隔。 If it is not possible to "clean" the URLs, it might become too long as there will be GET parameters and location hash parameters as well. 如果无法“清理” URL,则可能会变得太长,因为还会有GET参数和位置哈希参数。

You could use a Servlet Filter with a HttpServletRequestWrapper . 您可以将Servlet FilterHttpServletRequestWrapper一起使用。

In its doFilter method, you can impact on the Request . 在其doFilter方法中,您可以影响Request

Here is the official documentation on the Filter interface, and here is the page about HttpServletRequestWrapper . 这是Filter接口的官方文档 ,这是有关HttpServletRequestWrapper页面

Finally, here is an good SO page about what you want to do. 最后, 是一个关于您想做什么的很好的SO页面。

GET参数是URL编码的,这就是它的定义方式http://www.w3schools.com/tags/ref_httpmethods.asp可以使用几种编码方法,例如base64 ,但是如果有的话,也可以将其解码某些要安全发送到服务器的信息,您可以使用POST方法,也可以在web.xml映射您的页面,并添加带有身份验证检查的过滤器,以避免用户玩耍。

What is your intention for not having request parameters appear in the URL? 您不希望在URL中显示请求参数的意图是什么? If it's purely aesthetics then you could always use REST style urls - much like Stackoverflow - where the parameters are tokens within the URL. 如果纯粹是美观的话,那么您始终可以使用REST样式的url(非常类似于Stackoverflow),其中参数是URL中的标记。

Otherwise I don't believe it's possible for a client to request a certain URL?param1=.... and then end up with just URL without either a redirect from the server or the original request was a POST. 否则,我不认为客户端可以请求某个URL?param1=....然后仅以URL结尾,而没有从服务器重定向或原始请求是POST。 Difference between POST and GET POST和GET之间的区别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM