- <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <style type="text/css">
- <!--
- .style1 {
- font-family: "宋体";
- font-size: 24px;
- font-weight: bold;
- }
- -->
- </style>
- </head>
- <body>
- <%
- if(session.getAttribute("userid")== null || session.getAttribute("userid").equals(""))
- {
- response.sendRedirect("index.jsp");
- }
- %>
- <jsp:include flush="true" page="head.jsp"/><br /><br /><br /><br />
- <form name="form1" method="post" action="StudAddSave.jsp" onSubmit="return check();">
- <table width="500" height="216" border="1" align="center" cellpadding="3" cellspacing="1">
- <caption>
- <span class="style1"> 新增学生资料
- </span>
- </caption>
- <tr>
- <td height="33" ><div align="right">学生编号:</div></td>
- <td><input name="studID" type="text" id="studID" size="20" maxlength="12"></td>
- </tr>
- <tr>
- <td height="35" ><div align="right">学生姓名:</div></td>
- <td><input name="studName" type="text" id="studName" size="20" maxlength="20"></td>
- </tr>
- <tr>
- <td height="35" ><div align="right">所在班级:</div></td>
- <td><select name="classID" id="classID" style="width:133px">
- <%!
- String classID="",className="";
- %>
- <%
- String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; //驱动程序,见第十四章
- String url="jdbc:odbc:stud";//数据库连接语句,见第十四章
- String userID="sa",pwd="",sql="";
- try{
- Class.forName(driver);//调入JDBC-ODBC桥的驱动程序
- Connection conn = DriverManager.getConnection(url,userID,pwd);//建立与数据的连接
- //request对象见第四章
- sql = "select * from class";
- Statement stmt = conn.createStatement();//建立Statement的实例,相当于创建一个查询分析器的运行环境
- ResultSet rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
- while(rs.next()){
- classID = rs.getString("classID");
- className=rs.getString("className");
- %>
- <option value="<%=classID%>"><%=className%></option>
- <% }
- }catch(Exception e){
- System.out.println(e.getMessage());
- }
- %>
- </select></td>
- </tr>
- <tr>
- <td height="36" ><div align="right">性 别:</div></td>
- <td><input name="sex" type="radio" value="男" checked>
- 男
- <input type="radio" name="sex" value="女">
- 女</td>
- </tr>
- <tr>
- <td width="301" height="39" ><div align="right">年龄:</div></td>
- <td width="446"><input name="age" type="text" id="age" size="20" maxlength="3"></td>
- </tr>
- <tr>
- <td colspan="2"><div align="center">
- <input type="submit" name="Submit" value=" 保 存 ">
- </div></td>
- </tr>
- </table>
- </form>
- <jsp:include flush="true" page="bottom.jsp"/>
- </body>
- </html>
- <script language="javascript">
- function check()
- {
- if(form1.studID.value=="")
- {
- alert("请输入学生编号");
- form1.studID.focus();
- return false;
- }
- if(form1.studID.value.length>12)
- {
- alert("学生编号最大只能为12位");
- form1.studID.focus();
- return false;
- }
- if(form1.studName.value=="")
- {
- alert("请输入学生姓名");
- form1.studName.focus();
- return false;
- }
- if(form1.age.value=="")
- {
- alert("请输入学生年龄");
- form1.age.focus();
- return false;
- }
- if(isNaN(form1.age.value))
- {
- alert("学生年龄含有非法字符");
- form1.age.focus();
- return false;
- }
- return true;
- }
- </script>