StudList.jsp
上传用户:jhoneliu
上传日期:2022-07-31
资源大小:950k
文件大小:3k
- <%@ 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="StudAdd.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>
- <td><div align="center">所在班级</div></td>
- <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 s.*,c.classname,m.majorname,d.depname from studinfo s left outer join class c on s.classid=c.classid left outer join major m on m.majorid=c.majorid left outer join department d on d.depid=m.depid";
- Statement stmt = conn.createStatement();//建立Statement的实例,相当于创建一个查询分析器的运行环境
- ResultSet rs = stmt.executeQuery(sql); //把查询结果放入ResultSet对象
- String studId="",studName="",classid="",sex="",age="",majorname="",depname="";
- while(rs.next()){
- studId=rs.getString("StudID");
- studName=rs.getString("StudName");
- sex=rs.getString("Sex");
- age=rs.getString("Age");
- classid=rs.getString("ClassName");
- majorname=rs.getString("majorname");
- depname=rs.getString("depname");
- %>
- <tr>
- <td><div align="center"><%=depname%></div></td>
- <td><div align="center"><%=majorname%></div></td>
- <td><div align="center"><%=studId%></div></td>
- <td><div align="center"><%=studName%></div></td>
- <td><div align="center"><%=classid%></div></td>
- <td><div align="center"><%=sex%></div></td>
- <td><div align="center"><%=age%></div></td>
- <td><div align="center"><a href="StudEdit.jsp?studId=<%=studId%>">修改资料</a></div></td>
- <td><div align="center"><a href="StudDel.jsp?studId=<%=studId%>" 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>