我想在我的 JSP 上使用下拉菜单,但是...我不知道如何捕获所选项目的值并将其传递到我的 Servlet,并有一些查询将值添加到我的数据库中。
你能给我一些想法或线索如何编码吗?
附言。我还需要将下拉菜单中的项目转换为整数,因为我会将其添加到数据库中的存储数据中。
这对像我这样的初学者来说会很难吗? 我应该使用文本框并让用户手动输入整数而不是下拉菜单吗?
提前致谢:)
我的 Jsp 菜单是这样的:
<body>
<form action="AddPoints">
<table width="408" border="0">
<tr>
<td width="402"><h3 align="center">Enter Points:</h3>
<h3 align="center">
<label for="Points"></label>
<select name="Points" size="1" id="Points">
<option value="5" selected>5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
</select>
<br/>
</h3>
<h3 align="center"><strong></strong>
<input type="submit" name="AddPoints" id="AddPoints" value="Add Points">
</h3></td>
</tr>
</table>
</form>
</body>
我还想知道这一行的值:<option value="25">25</option>
是我的 servlet 可以捕获的真正值(value)吗?
对不起,如果我有这么多问题......:)
最佳答案
int selectedItem;
if(request.getParameter("Points")!=null)
{
selectedItem=Integer.ParseInt(request.getParameter("Points"));
}
关于jsp - 如何从 jsp 的 DropDown 菜单中捕获值到 Servlet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5312936/