⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 check.jsp

📁 数据结构考试 网站(jsp)
💻 JSP
字号:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%
	String snumber = request.getParameter("snumber");
	int studentnumber = 0;
	int attendnumber = 0;
	String password = null;
	String absentstudent[] = new String[100];
	int i = 0;
%>
<%
	try {
			String driverName="com.mysql.jdbc.Driver";      //驱动程序名
			String userName="root";                         //数据库用户名
			String userPwd="root";                        //密码
		    String dbName="dstester";                        //数据库名
		    String url="jdbc:mysql://localhost/"+dbName+
		                    "?user="+userName+"&password="+userPwd;    //连接字符串
		    Connection conn = null;                          //数据库连接对象
		    Statement stmt = null;                               //数据库语句对象
		    ResultSet rs = null;
		    // 建立数据库连接

	    	 try {
	    		 Class.forName(driverName).newInstance();
	        	 conn=DriverManager.getConnection(url);  //获得数据库连接
	        	 stmt=conn.createStatement();
	         } catch(Exception e) {
	    		 e.printStackTrace();		 
	        	 out.print("数据库连接失败!");
	    	 }
			try{	
				//查询总共考生人数
				rs = stmt.executeQuery("select count(snumber) from student");
				while(rs.next())
					studentnumber = rs.getInt(1);
				//查询参加考试考生人数
				rs = stmt.executeQuery("select count(snumber) from results");
				while(rs.next())
					attendnumber = rs.getInt(1);
				
				//考生密码查询
				if(snumber != null)
				{
					rs = stmt.executeQuery("select password from results where snumber='"+snumber+"'");
					if(rs.next())
						{
							password = rs.getString(1);
						}
						
				}
				
				rs = stmt.executeQuery("select snumber from student where snumber not in(select snumber from results)");
				
				while(rs.next())
					{
						absentstudent[i] = rs.getString(1);
						i++;
					}
				}catch (Exception e) {
					System.out.println("抛出异常:  "+e.getMessage());
				}
			

			try {
				if (stmt != null) {
					stmt.close();
				}
				conn.close();
			} catch (SQLException SqlE) {
				SqlE.printStackTrace();
				out.print("数据库关闭失败!");
			}

		} catch (Exception e) {
			System.out.println("抛出异常:  "+e.getMessage());
		}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  
    <title>考生信息</title>
    <style type="text/css">
<!--
.STYLE1 {
	font-family: "微软雅黑";
	font-size: 24px;
	font-weight: bold;
}
.STYLE2 {
	font-family: "微软雅黑";
	font-weight: bold;
}
.STYLE4 {font-family: "微软雅黑"; font-weight: bold; color: #FF0000; }
-->
    </style>
</head>
  
  <body>
  <table width="200" border="0" align="center">
    <tr>
      <td height="80" align="center" valign="middle"><span class="STYLE1">&nbsp;考试信息</span></td>
    </tr>
  </table>
  
  <form name="form" action="check.jsp" method="post">
  <table width="300" border="0" align="center">
    <tr>
      <td width="118" align="left"><span class="STYLE2">考生人数:</span></td>
      <td width="172"><span class="STYLE2">
        <%out.print(studentnumber); %>
        人</span></td>
    </tr>
    <tr>
      <td><span class="STYLE2">实际参考人数:</span></td>
      <td><span class="STYLE2">
        <%out.print(attendnumber); %> 
      </span></td>
    </tr>
    <tr>
      <td><span class="STYLE2">缺考人数:</span></td>
      <td><span class="STYLE2">
        <%out.print(studentnumber-attendnumber); %>
      人</span></td>
    </tr>
    <tr>
      <td><span class="STYLE2">缺考考生学号:</span></td>
      <td>
      	<span class="STYLE4">
      	<% 
			for(int j = 0;j < i;j++)
				out.print(absentstudent[j]+"   ");
		%>
        </span></td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td><span class="STYLE2">考生密码查询</span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span class="STYLE2">考生学号:</span></td>
      <td><input type="text" name="snumber">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" value="查询"></td>
    </tr>
    <%if(snumber != null){ %>
    <tr>
      <td><span class="STYLE2">该考生密码:</span></td>
      <td><span class="STYLE2">
      <%out.print(password);%>
      &nbsp;</span></td>
    </tr>
    <%} %>
  </table>
  </form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -