[英]How to fetch data that will be stored in the select option value in the form?
我想從數據庫中動態獲取或獲取數據並填充選擇框。 這是我的代碼:
<form action="addchangerequest" method="post">
<select name="type">
<option value="Non-Sap">Non-Sap</option>
<option value="Sap">Sap</option>
</select>
<select name="assettriggered">
** I want to populate these option values upon making a selection to the first select box. These option will be the data coming from the database**
</select>
</form>
這是我的方法類。
public List sortDeployed(String userID)
{
List deployedlist = new ArrayList();
try
{
PreparedStatement pstmt = conn.prepareStatement(SORT_ID);
pstmt.setString(1, userID);
ResultSet rs = pstmt.executeQuery();
while(rs.next())
{
StoreAssetBean storeAssetBean = new StoreAssetBean();
storeAssetBean.setDeployedID(rs.getInt("AssetDeployed_ID"));
storeAssetBean.setName(rs.getString("Asset_Name"));
storeAssetBean.setMmoID(rs.getString("UserDivision_ID"));
storeAssetBean.setDepartment(rs.getString("User_Department"));
storeAssetBean.setDepType(rs.getString("AssetDeployed_Type"));
storeAssetBean.setDeployedDateTime(rs.getString("AssetDeployed_DateTime"));
deployedlist.add(storeAssetBean);
}
}
catch(SQLException e)
{
System.out.println(e);
}
return deployedlist;
}
我希望必須將AssetDeployed_Type數據導入名為“ assettriggered”的選擇框。 我正在使用MVC Model 2 JSP Servlet。 我已經搜索過有關ajax的信息,但是我沒有實現它的經驗。 當我在第一個選擇框中選擇值時,我希望它是動態數據獲取。 請幫助我,謝謝你!
當您了解需要采取的步驟時,這很容易做到。
<select>
onchange
。 當然,您可以自己發送XMLHttpRequest
,但是通過使用成熟的JS庫(如jQuery),這樣做更容易(且更穩定)。 <select>
元素的所選<option>
的值,並且可能是獲取操作的id。 從servlet返回的數據以JSON格式序列化可以通過使用類似Gson的庫來完成。 <select>
元素)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.