<a> 不能像您认为的那样使用。它不是依赖于 <form> 提交的 HTML 元素之一,例如 <input>、<textarea>、<select> 等。
您可以阅读有关使用 <a> here 以及如何在 URL here 中传递请求参数的更多信息。还有一些关于HTML form and its elements。
所以如果你的代码是这样的:
<form action="/AddDescriptionForEvent.jsp" name="myForm">
<td>
<input type="text" name="someText" value="some Value" />
</td>
<td>
<span>
<a href="AddDescriptionForEvent.jsp?" name="count"><%=(cnt)%></a>
<span>
</td>
<input type="submit" value="Press me to Submit" />
</form>
然后单击submit 按钮,您只会发送输入someText 的值,而不是count。
要将count 的值与其他值一起发送,请使用以下格式:
<form action="/AddDescriptionForEvent.jsp" name="myForm">
<td>
<input type="text" name="someText" value="some Value" />
</td>
<td>
<span>
<!-- changed the <a> tag to <input> -->
<input type="text" name="count" value="<%=(cnt)%>" />
<span>
</td>
<input type="submit" value="Press me to Submit" />
</form>
或者您可以使用以下不带<form>:
<td>
<span>
<a href="AddDescriptionForEvent.jsp?count=<%=cnt%>">Click this link to Add</a>
<span>
</td>
<!-- Notice the placement of the "cnt" variable of JSP -->
若要在单击此<a> 链接时也传递其他参数,请将href 修改为href="AddDescriptionForEvent.jsp?count=<%=cnt%>&someText=some value"
您可以通过以下两种方式获得所需的结果。您获取请求参数的 java 代码很好。