1. 程式人生 >實用技巧 >其它 >select下拉框獲取值

select下拉框獲取值


select下拉框的使用

下拉框獲取固定的值

 <select name="projectKind" lay-verify="required">
        <option value="">請選擇專案型別</option>
        <option value="創新型">創新型</option>
        <option value="公益型">公益型</option>
        <option value="公益型">創意型</option>
      </select>

select下拉框獲取值

下拉框獲取資料庫的值

 <select name="positionSid" lay-verify="required" id="id">
                    <option value="" selected="selected">請選擇學生學號</option>

<%
                   //連線資料庫
                  String driverName="com.Mysql.cj.jdbc.Driver";    //Mysql資料庫連線
                  String userName="root";
                  String psw="010802";     //本行和上一行是資料庫的登入名和密碼
                  String dbName="koko";	   //資料庫名字
                  String url="jdbc:mysql://localhost:3306/koko?serverTimezone=UTC&characterEncoding=UTF-8&useUnicode=true&useSSL=false";
                            Class.forName(driverName);
                            Connection    conn=DriverManager.getConnection(url,userName,psw);
                             String strSql="select * from student";
                            Statement   stat=conn.createStatement();
                            ResultSet   rs=stat.executeQuery(strSql);
                            while(rs.next())   //迴圈輸出資料
                            {
                              String s = rs.getString("sid");
                              %>

                    <option value="<%= s%>"><%= s%></option>
                     <%
                        }
                    %>
                </select>