How can I submit a POST form to showMessage.jsp
using just the <a href="...">
tag?
<form action="showMessage.jsp" method="post"> <a href="showMessage.jsp"><%=n%></a> <input type="hidden" name="mess" value=<%=n%>/> </form>
There is no way to POST an a element using only HTML. There is no attribute that controls whether to use POST or GET with an a element. You have to script it, if you want to abuse the semantics.
The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.
This behaviour is specific to display tag library. It allows for easily bookmarkable search results. If you really intend to change this to make use of POST, then you'd need to rewrite the display tag library or bring in some jQuery to manipulate the links. The remnant of your questions boils nowhere.
POST is used to send data to a server to create/update a resource. Some notes on POST requests: POST requests are never cached.
No JavaScript needed if you use a button instead:
<form action="your_url" method="post"> <button type="submit" name="your_name" value="your_value" class="btn-link">Go</button> </form>
You can style a button to look like a link, for example:
.btn-link { border: none; outline: none; background: none; cursor: pointer; color: #0000EE; padding: 0; text-decoration: underline; font-family: inherit; font-size: inherit; }
You need to use javascript for this.
<form id="form1" action="showMessage.jsp" method="post"> <a href="javascript:;" onclick="document.getElementById('form1').submit();"><%=n%></a> <input type="hidden" name="mess" value=<%=n%>/> </form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With