majorEdit.jsp
上传用户:jhoneliu
上传日期:2022-07-31
资源大小:950k
文件大小:3k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  5. </head>
  6. <body>
  7.   <%
  8. if(session.getAttribute("userid")== null || session.getAttribute("userid").equals(""))
  9. {
  10.   response.sendRedirect("index.jsp");
  11. }
  12. %>
  13. <jsp:include flush="true" page="head.jsp"/><br />
  14. <form name="form1" method="post" action="majorEditSave.jsp" onSubmit="return check();">
  15. <%!
  16. String majorname="",majorid="",depid="";
  17. ResultSet rs=null,rs1=null;
  18. Statement stmt=null;
  19.  %>
  20. <%
  21. String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; //驱动程序,见第十四章
  22. String url="jdbc:odbc:stud";//数据库连接语句,见第十四章
  23. String userID="sa",pwd="",sql="";
  24. try{
  25.   Class.forName(driver);//调入JDBC-ODBC桥的驱动程序
  26.   Connection conn = DriverManager.getConnection(url,userID,pwd);//建立与数据的连接
  27.   //request对象见第四章
  28.   stmt = conn.createStatement();//建立Statement的实例,相当于创建一个查询分析器的运行环境
  29.   sql = "select * from major where majorid='" + request.getParameter("majorId") + "'";
  30.   rs1  = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
  31.   if(rs1.next()){
  32.     majorid=rs1.getString("majorid");
  33.     majorname=rs1.getString("majorname");
  34.     depid=rs1.getString("depid");
  35.   }
  36.  }catch(Exception e){
  37.   System.out.println(e.getMessage());
  38. }
  39.   %>
  40. <input type="hidden" name="majorID" value="<%=majorid%>"/>
  41.   <table width="500" height="104" border="1" align="center" cellpadding="3" cellspacing="1">
  42.     <caption>
  43.     修改专业资料
  44.     </caption>
  45.     <tr>
  46.       <td height="50"><div align="right">所属分院:</div></td>
  47.       <td><select name="depId" style="width:133px">
  48.       <%
  49.       String tempdepid="",depname="";
  50.       try{
  51.         sql = "select * from Department";
  52.         rs  = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
  53.         while(rs.next())
  54.         {
  55.           tempdepid = rs.getString("depid");
  56.           depname = rs.getString("depname");
  57.           if(tempdepid.equals(depid)){
  58. %>
  59. <option value="<%=tempdepid%>" selected="selected"><%=depname%></option>
  60. <%
  61.           }else{
  62. %>
  63. <option value="<%=tempdepid%>"><%=depname%></option>
  64. <%
  65.           }
  66.         }
  67.       }catch(Exception e){}
  68.       %>
  69.       </select></td>
  70.     </tr>
  71.     <tr>
  72.       <td width="301" height="50"><div align="right">专业名称:</div></td>
  73.       <td width="446"><input name="majorName" type="text" id="majorName"  value="<%=majorname%>" maxlength="20"></td>
  74.     </tr>
  75.     <tr>
  76.       <td colspan="2"><div align="center">
  77.         <input type="submit" name="Submit" value="  保  存   ">
  78.       </div></td>
  79.     </tr>
  80.   </table>
  81. </form>
  82. <jsp:include flush="true" page="bottom.jsp"/>
  83. </body>
  84. </html>
  85. <script language="javascript">
  86. function check()
  87. {
  88. if(form1.majorName.value=="")
  89. {
  90. alert("请输入专业名称");
  91. form1.majorName.focus();
  92. return false;
  93. }
  94. return true;
  95. }
  96. </script>