简体   繁体   中英

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

This does not work. The action request isn't hit for some reason.

Does anyone have a different suggestion for hiding URL parameters?

<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. You cannot fire HTTP GET requests 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 POST requests instead of GET requests to take actions accordingly.

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.

You can using XMLHttpRequest to hide URL parameter or using session variable of servlet container.

Maybe you can using encode url to show complex data to end user.

good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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