Search code examples
servletsanchorhttprequesthttp-request-parameters

How to send a parameter over http request using an anchor tag


I want to send a parameter value over http using <a> tag but I do not want it to be set in the href attribute.

Is there a way to do just that so that I could receive that value on the server side?

Thanks.


Solution

  • Either use JS to submit a (hidden) form.

    <form id="foo" method="post" action="servletURL">
        <input type="hidden" name="yourParamName" value="yourParamValue" />
    </form>
    <a href="#" onclick="document.getElementById('foo').submit(); return false;">link</a>
    

    Or use CSS to style the default submit button to look like a link.

    <form id="foo" method="post" action="servletURL">
        <input type="hidden" name="yourParamName" value="yourParamValue" />
        <input type="submit" value="link" class="link" />
    </form>
    

    with

    input[type=submit].link {
        margin: 0;
        border: 0;
        background: transparent;
        color: blue;
        text-decoration: underline;
        cursor: pointer;
        overflow: visible;
    }