我想在JSP页面上显示多个下拉菜单。第一个下拉列表显示了数据,但是第二个下拉列表没有显示数据。控制台没有透露任何信息。
数据库:
CREATE TABLE "HAI"."SERVICE"
( "SERVICEID" NUMBER(3,0) NOT NULL ENABLE,
"SERVICENAME" VARCHAR2(100 BYTE),
"SERVICEPRICE" BINARY_DOUBLE,
这里是来自jsp的代码:
<table>
<tr>
<td>
Select Service Name:
<select name="serviceName">
<option selected = "selected">Select Name</option>
<%
try{
String query = "SELECT * FROM SERVICE";
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hai","admin");
Statement stm = con.createStatement();
ResultSet rs = stm.executeQuery(query);
while(rs.next())
{
%>
<option value="<%=rs.getInt("serviceId")%>"><%=rs.getString("serviceName")%></option>
<%
}
}
catch(Exception ex){
ex.printStackTrace();
}
%>
</select>
</td>
<td>
Select Service Price:
<select name="servicePrice">
<option selected="selected">select Price</option>
<%
try{
String sql = "SELECT * FROM SERVICE WHERE SERVICEID=?";
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hai","admin");
PreparedStatement psmt = con.prepareStatement(sql);
psmt.setString(1,request.getParameter("service"));
ResultSet rs = psmt.executeQuery();
while(rs.next())
{
%>
<option value="<%=rs.getInt("serviceId")%>"><%=rs.getDouble("servicePrice") %></option>
<%
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
%>
</select>
</td>
</tr>
</table>
我希望第一个下拉列表与第二个下拉列表连接。例如,如果我选择诸如“干洗”之类的服务名称,则该服务价格将自动上涨。我正在使用jsp,javascript和servlet。