How can I submit a POST form to showMessage.jsp
using just the <a href="...">
tag?
如何向showMessage提交邮寄表格?jsp只使用标记?
<form action="showMessage.jsp" method="post">
<a href="showMessage.jsp"><%=n%></a>
<input type="hidden" name="mess" value=<%=n%>/>
</form>
5 个解决方案
#1
68
No JavaScript needed if you use a button instead:
如果您使用按钮,则不需要JavaScript:
<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;
}
#2
33
You have to use Javascript submit
function on your form
object. Take a look in other functions.
必须在表单对象上使用Javascript提交函数。看看其他函数。
<form action="showMessage.jsp" method="post">
<a href="javascript:;" onclick="parentNode.submit();"><%=n%></a>
<input type="hidden" name="mess" value=<%=n%>/>
</form>
#3
29
You need to use javascript for this.
为此需要使用javascript。
<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>
#4
2
In case you use MVC to accomplish it - you will have to do something like this
如果您使用MVC来完成它——您将不得不做这样的事情
<form action="/ControllerName/ActionName" method="post">
<a href="javascript:;" onclick="parentNode.submit();"><%=n%></a>
<input type="hidden" name="mess" value=<%=n%>/>
</form>
I just went through some examples here and did not see the MVC one figured it won't hurt to post it.
我只是在这里浏览了一些例子,并没有看到MVC,我认为发布它不会有什么坏处。
Then on your Action in the Controller I would just put <HTTPPost>
On the top of it. I believe if you don't have <HTTPGET>
on the top of it it would still work but explicitly putting it there feels a bit safer.
然后,在控制器中的操作上,我只需将
#5
0
There really seems no way for fooling the <a href= ..
into a POST method. However, given that you have access to CSS of a page, this can be substituted by using a form instead.
Unfortunately, the obvious way of just styling the button in CSS as an anchor tag, is not cross-browser compatible, since different browsers treat <button value= ...
differently.
不幸的是,将CSS中的按钮作为锚标记的明显方式,不是跨浏览器兼容的,因为不同的浏览器处理
Incorrect:
<form action='actbusy.php' method='post'>
<button type='submit' name='parameter' value='One'>Two</button>
</form>
The above example will be showing 'Two' and transmit 'parameter:One' in FireFox, while it will show 'One' and transmit also 'parameter:One' in IE8.
上面的示例将在FireFox中显示“Two”并传输“parameter:One”,而在IE8中,它将显示“One”并传输“parameter:One”。
The way around is to use hidden input field(s) for delivering data and the button just for submitting it.
方法是使用隐藏的输入字段(s)来传递数据,并使用按钮来提交数据。
<form action='actbusy.php' method='post'>
<input class=hidden name='parameter' value='blaah'>
<button type='submit' name='delete' value='Delete'>Delete</button>
</form>
Note, that this method has a side effect that besides 'parameter:blaah' it will also deliver 'delete:Delete' as surplus parameters in POST.
注意,这个方法有一个附加的效果,除了“参数:blaah”,它还会发送“delete: delete”作为POST中的剩余参数。
You want to keep for a button the value attribute and button label between tags both the same ('Delete' on this case), since (as stated above) some browsers will display one and some display another as a button label.
您希望为按钮保留标记之间的值属性和按钮标签(在本例中是“Delete”),因为(如上所述)一些浏览器将显示一个,另一些浏览器将显示另一个作为按钮标签。
#1
68
No JavaScript needed if you use a button instead:
如果您使用按钮,则不需要JavaScript:
<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;
}
#2
33
You have to use Javascript submit
function on your form
object. Take a look in other functions.
必须在表单对象上使用Javascript提交函数。看看其他函数。
<form action="showMessage.jsp" method="post">
<a href="javascript:;" onclick="parentNode.submit();"><%=n%></a>
<input type="hidden" name="mess" value=<%=n%>/>
</form>
#3
29
You need to use javascript for this.
为此需要使用javascript。
<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>
#4
2
In case you use MVC to accomplish it - you will have to do something like this
如果您使用MVC来完成它——您将不得不做这样的事情
<form action="/ControllerName/ActionName" method="post">
<a href="javascript:;" onclick="parentNode.submit();"><%=n%></a>
<input type="hidden" name="mess" value=<%=n%>/>
</form>
I just went through some examples here and did not see the MVC one figured it won't hurt to post it.
我只是在这里浏览了一些例子,并没有看到MVC,我认为发布它不会有什么坏处。
Then on your Action in the Controller I would just put <HTTPPost>
On the top of it. I believe if you don't have <HTTPGET>
on the top of it it would still work but explicitly putting it there feels a bit safer.
然后,在控制器中的操作上,我只需将
#5
0
There really seems no way for fooling the <a href= ..
into a POST method. However, given that you have access to CSS of a page, this can be substituted by using a form instead.
Unfortunately, the obvious way of just styling the button in CSS as an anchor tag, is not cross-browser compatible, since different browsers treat <button value= ...
differently.
不幸的是,将CSS中的按钮作为锚标记的明显方式,不是跨浏览器兼容的,因为不同的浏览器处理
Incorrect:
<form action='actbusy.php' method='post'>
<button type='submit' name='parameter' value='One'>Two</button>
</form>
The above example will be showing 'Two' and transmit 'parameter:One' in FireFox, while it will show 'One' and transmit also 'parameter:One' in IE8.
上面的示例将在FireFox中显示“Two”并传输“parameter:One”,而在IE8中,它将显示“One”并传输“parameter:One”。
The way around is to use hidden input field(s) for delivering data and the button just for submitting it.
方法是使用隐藏的输入字段(s)来传递数据,并使用按钮来提交数据。
<form action='actbusy.php' method='post'>
<input class=hidden name='parameter' value='blaah'>
<button type='submit' name='delete' value='Delete'>Delete</button>
</form>
Note, that this method has a side effect that besides 'parameter:blaah' it will also deliver 'delete:Delete' as surplus parameters in POST.
注意,这个方法有一个附加的效果,除了“参数:blaah”,它还会发送“delete: delete”作为POST中的剩余参数。
You want to keep for a button the value attribute and button label between tags both the same ('Delete' on this case), since (as stated above) some browsers will display one and some display another as a button label.
您希望为按钮保留标记之间的值属性和按钮标签(在本例中是“Delete”),因为(如上所述)一些浏览器将显示一个,另一些浏览器将显示另一个作为按钮标签。