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

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

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

		return;
	}
		
 	sql = "select * from test_admin where loginname='" + username;
	sql+= "' and password='" + password + "'";

	try {
			rs = conn.executeQuery( sql );
	
			// 如果是非法用户名或密码，回到登陆界面
			if(!rs.next()) {
%>
				<jsp:forward page="/admin/index.jsp">
	               <jsp:param name="errmsg" value="Invalid username or password"/>
				</jsp:forward>
<%			    
			}
			priv = rs.getInt("priviledge");                  // 得到用户权限
	
	}catch(Exception ee) { // 其他异常情况
System.out.println( ee.toString() );
%>
				<jsp:forward page="/public/dberror.jsp"/>
<%			    
	}
	session.setAttribute("adminpriv", priv + "");        // 将权限信息保存到session中
    session.setAttribute("adminname", username);         // 将管理员登录信息保存到session中
	session.setMaxInactiveInterval(60*60*24);
	response.sendRedirect("/test/admin/manager.jsp");   
%>