我想在我的JSP上使用下拉菜單,但是......我不知道如何捕獲所選項目的值並將其傳遞給我的Servlet,並有一些QUERY將值添加到我的數據庫。如何從jsp的DropDown菜單捕獲值到Servlet?
你能給我一些想法或線索如何編碼嗎?
PS。我還需要下拉菜單中的項目轉換爲Integer,因爲我將它添加到我的數據庫中存儲的數據。
這對於像我這樣的初學者來說會很難嗎? 我應該使用Textbox並讓用戶手動輸入INTEGER而不是下拉菜單嗎?
感謝很多提前:)
我的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可以捕獲?
很抱歉,如果我有這麼多的問題... :)
更好的設計是保持在服務器端的選項值和其標籤像'的ServletContextListener '或者某種。檢查[http://stackoverflow.com/questions/8840655/how-get-selected-option-label-from-a-dropdown-list] –