简体   繁体   English

如何隐藏我的网址参数?

[英]How to hide my url params?

I've got several Portlets with some links in them, all I want is to hide the URL params. 我有几个带有一些链接的Portlet,我想要的就是隐藏URL参数。 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. 因此,我认为包含一些jQuery代码会很容易,这些代码会为每个jQuery代码构建一个表单,并在其上绑定一个click事件以提交表单。

This does not work. 这是行不通的。 The action request isn't hit for some reason. 由于某种原因,该操作请求未得到满足。

Does anyone have a different suggestion for hiding URL parameters? 有没有人建议隐藏URL参数?

<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>

Links fire GET requests by default. 默认情况下,链接会触发GET请求。 You cannot fire HTTP GET requests without passing parameters through the URL. 如果不通过URL传递参数,则无法触发HTTP GET请求。 The only what can do this is HTTP POST . 唯一可以做到这一点的就是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 POST requests instead of GET requests to take actions accordingly. 但是您需要用按钮将所有链接替换为表单,并且需要修改服务器端代码,以便它侦听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. Javascript也可以借助XMLHttpRequest在“后台”触发GET请求,但是当客户端禁用JS时,您的应用程序将中断或仍然显示参数。 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. 客户端也可以完全控制JS代码,因此不必从客户端“隐藏”参数,而只能从浏览器地址栏中“隐藏”参数。

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 祝好运

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

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