DepList.jsp
上传用户:jhoneliu
上传日期:2022-07-31
资源大小:950k
文件大小:2k
- <%@ 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 />
- <p align="center"><strong><font size="4" color="#FF0000"">部门资料列表</font></strong></p>
- <table width="768" border="0" align="center" cellpadding="3" cellspacing="1">
- <tr><td><a href="DepAdd.jsp">新增</a></td></tr>
- </tr>
- </table>
- <table width="768" border="1" align="center" cellpadding="3" cellspacing="1">
- <tr>
- <td><div align="center">部门编号</div></td>
- <td><div align="center">部门名称 </div></td>
- <td><div align="center">修改资料</div></td>
- <td><div align="center">删除资料</div></td>
- </tr>
- <%
- 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 Department";
- Statement stmt = conn.createStatement();//建立Statement的实例,相当于创建一个查询分析器的运行环境
- ResultSet rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
- String depid="";
- while(rs.next()){
- depid=rs.getString("DepID");
- %>
- <tr>
- <td><div align="center"><%=depid%></div></td>
- <td><div align="center"><%=rs.getString("DepName")%></div></td>
- <td><div align="center"><a href="DepEdit.jsp?DepID=<%=depid%>">修改资料</a></div></td>
- <td><div align="center"><a href="DepDel.jsp?DepID=<%=depid%>" onclick="return check();">删除资料</a></div></td>
- </tr>
- <%}
- }catch(Exception e){
- System.out.println(e.getMessage());
- }
- %>
- </table><br />
- <jsp:include flush="true" page="bottom.jsp"/>
- </body>
- </html>
- <script language="javascript">
- function check()
- {
- if(confirm("删除确认"))
- {
- return true;
- }
- return false;
- }
- </script>