java 如何隐藏我的网址参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1716649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide my url params?
提问by onigunn
I've got several Portlets with some links in them, all I want is to hide the URL params. So I thought it would be easy to include some jQuery code, which builds a form for each and binds a click event on it to submit the form.
我有几个带有一些链接的 Portlet,我只想隐藏 URL 参数。所以我认为包含一些 jQuery 代码会很容易,它为每个构建一个表单并在其上绑定一个单击事件以提交表单。
This does not work. The action request isn't hit for some reason.
这不起作用。由于某种原因未命中操作请求。
Does anyone have a different suggestion for hiding URL parameters?
有没有人对隐藏 URL 参数有不同的建议?
回答by Shailesh Kumar
<a href="#" onclick="JavaScript: handleThisLink();"> description of link </a>
<form name="mydataform" id="mydataform" action="/actionurlonyoursite" method="post">
<input type="hidden" name="myparam" value="" />
</form>
<script type="text/javascript">
function handleThisLink()
{
// access the hidden element in which you wish to pass the value of the parameter
dojo.byId("myparam").value = "myvalue";
// the value might be precomputed (while generating this page) or
// might need to be computed based on other data in the page
// submit the form by HTTP POST method to the URL which will handle it.
document.forms['mydataform'].submit();
// also possible to actually send a background AJAX request and publish
// the response to some part of the current page, thus avoiding full
// page refresh
// I used dojo.byId() as a shortcut to access the input element
// this is based on dojo toolkit.
}
</script>
回答by BalusC
Links fire GETrequests by default. You cannot fire HTTP GETrequests without passing parameters through the URL. The only what can do this is HTTP POST. All parameters are then included in the request body. But you would need to replace all links by forms with buttons and you need to modify the server side code so that it listens on POSTrequests instead of GETrequests to take actions accordingly.
GET默认情况下链接触发请求。您不能在不GET通过 URL 传递参数的情况下触发 HTTP请求。唯一可以做到这一点的是 HTTP POST。然后所有参数都包含在请求正文中。但是您需要用按钮替换表单中的所有链接,并且您需要修改服务器端代码,以便它侦听POST请求而不是GET请求以相应地采取行动。
Javascript can also fire GET requests just in "the background" with help of XMLHttpRequest, but when a client has JS disabled, your application will either break or still display the parameters. Also the client has full control over JS code, so it does not necessarily "hide" the parameters from the client, but only from the browser address bar.
Javascript 也可以在 的帮助下在“后台”触发 GET 请求XMLHttpRequest,但是当客户端禁用 JS 时,您的应用程序将中断或仍然显示参数。此外,客户端对 JS 代码具有完全控制权,因此它不一定对客户端“隐藏”参数,而仅对浏览器地址栏进行“隐藏”。
回答by misamap
You can using XMLHttpRequest to hide URL parameter or using session variable of servlet container.
您可以使用 XMLHttpRequest 隐藏 URL 参数或使用 servlet 容器的会话变量。
Maybe you can using encode url to show complex data to end user.
也许您可以使用编码 url 向最终用户显示复杂的数据。
good luck
祝你好运

