JSP连接SQL做select下拉菜单时,value与option的值相同时,总是显示option外的值有误
JSP连接SQL做select下拉菜单时,value与option的值相同时,总是显示option外的值有误,请帮我改下吧!谢谢~~
<select name="name"> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:tscgdb","sa","sa"); Statement stat = con.createStatement(); ResultSet rs = stat.executeQuery("select * from books"); while(rs.next()){ %> <option value="<%=rs.getString("bookname")%>"> <%=rs.getString("bookname")%></option> <% } rs.close(); %> </select>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:tscgdb","sa","sa"); Statement stat = con.createStatement(); ResultSet rs = stat.executeQuery("select * from books"); while(rs.next()){ String name = rs.getString("bookname"); %> <option value="<%=name%>"> <%=name%></option> <% } rs.close(); %>