我想动态地从数据库中获取或获取数据并填充选择框。这是我的代码:
<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 模型 2 JSP Servlet。我搜索过ajax,但我没有实现它的经验。当我在第一个选择框中选择值时,我希望它是动态数据获取。请各位大侠帮忙,先谢谢了!!