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

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.     response.sendRedirect("index.jsp");
  10.   }
  11. %>
  12. <jsp:include flush="true" page="head.jsp"/>
  13. <br/>
  14. <br/>
  15. <br/>
  16. <br/>
  17. <form name="form1" method="post" action="MajorCourseEditSave.jsp">
  18. <input type="hidden" name="recID" value="<%=request.getParameter("recId")%>">
  19. <table width="500" height="104" border="1" align="center" cellpadding="3" cellspacing="1">
  20.   <caption>修改专业课程  </caption>
  21.   <tr>
  22.     <td height="50">
  23.       <div align="right">专业名称:</div>
  24.     </td>
  25.     <td>
  26.       <select name="MajorID" id="MajorID" style="width:133px">
  27.       <%!
  28.         String MajorName = "", MajorID = "", CourseName = "", CourseID = "", tempmajorid = "", tempcourseid = "";
  29.         ResultSet rs = null;
  30.         Statement stmt = null;
  31.       %>
  32.       <%
  33.         String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; //驱动程序,见第十四章
  34.         String url = "jdbc:odbc:stud"; //数据库连接语句,见第十四章
  35.         String userID = "sa", pwd = "", sql = "";
  36.         try {
  37.           Class.forName(driver); //调入JDBC-ODBC桥的驱动程序
  38.           Connection conn = DriverManager.getConnection(url, userID, pwd); //建立与数据的连接
  39.           //request对象见第四章
  40.           stmt = conn.createStatement(); //建立Statement的实例,相当于创建一个查询分析器的运行环境
  41.           sql = "select * from majorcourse where recid=" + request.getParameter("recId");
  42.           rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
  43.           rs.next();
  44.           tempmajorid = rs.getString("MajorID");
  45.           tempcourseid = rs.getString("CourseID");
  46.           rs.close();
  47.           sql = "select * from Major";
  48.           rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
  49.           while (rs.next()) {
  50.             MajorID = rs.getString("MajorID");
  51.             MajorName = rs.getString("MajorName");
  52.             if (MajorID.equals(tempmajorid)) {
  53.       %>
  54.         <option value="<%=MajorID%>" selected="selected"><%=MajorName%>        </option>
  55.       <%
  56.         } else {
  57.       %>
  58.         <option value="<%=MajorID%>"><%=MajorName%>        </option>
  59.       <%
  60.         }
  61.         }
  62.         } catch (Exception e) {
  63.           System.out.println(e.getMessage());
  64.         }
  65.       %>
  66.       </select>
  67.     </td>
  68.   </tr>
  69.   <tr>
  70.     <td width="301" height="50">
  71.       <div align="right">课程名称:</div>
  72.     </td>
  73.     <td width="446">
  74.       <select name="CourseID" id="CourseID" style="width:133px">
  75.       <%
  76.         try {
  77.           rs.close();
  78.           sql = "select * from Course";
  79.           rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
  80.           while (rs.next()) {
  81.             CourseID = rs.getString("CourseID");
  82.             CourseName = rs.getString("CourseName");
  83.             if(CourseID.equals(tempcourseid)){
  84.       %>
  85.         <option value="<%=CourseID%>" selected="selected"><%=CourseName%>        </option>
  86.       <%
  87.             }else{
  88.       %>
  89.         <option value="<%=CourseID%>"><%=CourseName%>        </option>
  90.       <%
  91.             }}
  92.         } catch (Exception e) {
  93.           System.out.println(e.getMessage());
  94.         }
  95.         finally {
  96.           rs.close();
  97.         }
  98.       %>
  99.       </select>
  100.     </td>
  101.   </tr>
  102.   <tr>
  103.     <td colspan="2">
  104.       <div align="center">
  105.         <input type="submit" name="Submit" value=" 保  存 ">
  106.       </div>
  107.     </td>
  108.   </tr>
  109. </table>
  110. </form>
  111. <jsp:include flush="true" page="bottom.jsp"/>
  112. </body>
  113. </html>