- <%@ 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="StudEditSave.jsp" onSubmit="return check();">
- <%!
- String classID="",className="";
- String studid="",studname="",classid1="",sex="",age="";
- ResultSet rs = null;
- Statement stmt = null;
- %>
- <%
- 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 studinfo where studid='" + request.getParameter("studId") + "'";
- stmt = conn.createStatement();//建立Statement的实例,相当于创建一个查询分析器的运行环境
- rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
- if(rs.next())
- {
- studid= rs.getString("StudID");
- studname=rs.getString("StudName");
- classid1=rs.getString("ClassID");
- sex=rs.getString("Sex");
- age=rs.getString("Age");
- }
- rs.close();
- %>
- <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" readonly="true" value="<%=studid%>"></td>
- </tr>
- <tr>
- <td height="35" ><div align="right">学生姓名:</div></td>
- <td><input name="studName" type="text" id="studName" size="20" maxlength="20" value="<%=studname%>"></td>
- </tr>
- <tr>
- <td height="35" ><div align="right">所在班级:</div></td>
- <td><select name="classID" id="classID" style="width:133px">
- <%
- sql = "select * from class";
- stmt = conn.createStatement();//建立Statement的实例,相当于创建一个查询分析器的运行环境
- rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
- while(rs.next()){
- classID = rs.getString("classID");
- className=rs.getString("className");
- if(classID.equals(classid1)){
- %>
- <option value="<%=classID%>" selected="selected"><%=className%></option>
- <%
- }else{
- %>
- <option value="<%=classID%>"><%=className%></option>
- <%}
- }
- }catch(Exception e){
- System.out.println(e.getMessage());
- }
- %>
- </select></td>
- </tr>
- <% if( sex.equals("男")){%>
- <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>
- <%}else{%>
- <tr>
- <td height="36" ><div align="right">性 别:</div></td>
- <td><input name="sex" type="radio" value="男">
- 男
- <input type="radio" name="sex" value="女" checked>
- 女</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" value="<%=age%>"></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>