<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<jsp:useBean id="conn" scope="page" class="test.ConnOracle"/>

<%!
    ResultSet rs     = null;                 // 执行Sql语句返回的结果集
    String studentid  = "";
	String password   = "";
	String sql = "";
    int priv = 0;
%>
<%
    studentid = request.getParameter("studentid");
 	password  = request.getParameter("pwd");

	if(studentid ==null || password == null || studentid.equals("") || password.equals("")) {
        out.println( "<center>" );	
        out.println( "<h1>学员ID或密码输入非法！请返回重新输入！</h1><BR><BR>");	
        out.println("<a href=javascript:history.back()>返回</a>");
        out.println( "</center>" );	

		return;
	}
		
 	sql = "select * from test_studentinfo where studentid=" + studentid;
	sql+= " and password='" + password + "'";

	try {
			rs = conn.executeQuery( sql );
	
			// 如果是非法用户名或密码，回到登陆界面
			if(!rs.next()) {
%>
				<jsp:forward page="/"/>
<%			    
			}
	}catch(Exception ee) { // 其他异常情况
%>
				<jsp:forward page="/public/dberror.jsp"/>
<%			    
	}
	session.setAttribute("studentlogin","ok");        // 将权限信息保存到session中
	session.setAttribute("studentid",""+studentid);
    session.setAttribute("studentname",rs.getString("name"));
	session.setMaxInactiveInterval(60*60*24);
	response.sendRedirect("/test/test/exam.jsp");   
%>