- <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- </head>
- <body>
- <%
- if(session.getAttribute("userid")== null || session.getAttribute("userid").equals(""))
- {
- response.sendRedirect("index.jsp");
- }
- %>
- <jsp:include flush="true" page="head.jsp"/><br />
- <form name="form1" method="post" action="majorEditSave.jsp" onSubmit="return check();">
- <%!
- String majorname="",majorid="",depid="";
- ResultSet rs=null,rs1=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对象见第四章
- stmt = conn.createStatement();//建立Statement的实例,相当于创建一个查询分析器的运行环境
- sql = "select * from major where majorid='" + request.getParameter("majorId") + "'";
- rs1 = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
- if(rs1.next()){
- majorid=rs1.getString("majorid");
- majorname=rs1.getString("majorname");
- depid=rs1.getString("depid");
- }
- }catch(Exception e){
- System.out.println(e.getMessage());
- }
- %>
- <input type="hidden" name="majorID" value="<%=majorid%>"/>
- <table width="500" height="104" border="1" align="center" cellpadding="3" cellspacing="1">
- <caption>
- 修改专业资料
- </caption>
- <tr>
- <td height="50"><div align="right">所属分院:</div></td>
- <td><select name="depId" style="width:133px">
- <%
- String tempdepid="",depname="";
- try{
- sql = "select * from Department";
- rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
- while(rs.next())
- {
- tempdepid = rs.getString("depid");
- depname = rs.getString("depname");
- if(tempdepid.equals(depid)){
- %>
- <option value="<%=tempdepid%>" selected="selected"><%=depname%></option>
- <%
- }else{
- %>
- <option value="<%=tempdepid%>"><%=depname%></option>
- <%
- }
- }
- }catch(Exception e){}
- %>
- </select></td>
- </tr>
- <tr>
- <td width="301" height="50"><div align="right">专业名称:</div></td>
- <td width="446"><input name="majorName" type="text" id="majorName" value="<%=majorname%>" maxlength="20"></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.majorName.value=="")
- {
- alert("请输入专业名称");
- form1.majorName.focus();
- return false;
- }
- return true;
- }
- </script>