当前页面: 开发资料首页 → JSP 专题 → java中web页面的下拉列表框中数据怎样绑定数据库!
java中web页面的下拉列表框中数据怎样绑定数据库!
摘要: java中web页面的下拉列表框中数据怎样绑定数据库!
java中web页面的下拉列表框中数据怎样绑定数据库中的数据!
不明白你要问什么
下拉列表框中的数据,怎样从数据库中读取!
示例
<form method="post" name="form1" action="">
<select name="subject" id="subject">
<%
String url =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=stu";
String user = "sa";
String pass = "";
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
con = dbt.getConnection();
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(url, user, pass);
ps = con.prepareStatement("select subjectID,subject from subject");
rs = ps.executeQuery();
while(rs.next()) {
%>
<option value=<%=rs.getInt(1)%>><%=rs.getString(2).trim()%></option>
<%
}
} catch(Exception e) {
e.printStackTrace();
} finally {
rs.close();
ps.close();
con.close();
}
%>
</select>
</form>
这是STRUCT的方法呀,有没有JSF框架下的下拉列表框
,怎么样将数据绑上去?