<%@page contentType="text/html;charset=gb2312"%>
<%@page language="java"import="java.sql.*"%>
<jsp:useBean id="userBean"scope="page"class="regist.conn"/>
<%!
  public String getStr(String str)
  {
    try
     {
        String temp_p=str;
        byte[]temp_t=temp_p.getBytes("ISO8859-1");
        String temp=new String(temp_t);
        return temp;
     }
  catch(Exception e){}
  return "null";
  }
%>


<%!
   String logname,logpass;
   boolean loginAttempt=false;
   boolean loginOK=false;
   String errorMessage="请您登录";
%>


<%
  if(request.getParameterValues("login")!=null&&
     request.getParameterValues("logname")!=null&&
     request.getParameterValues("logpass")!=null)
    { loginAttempt=true; }
  
  if(loginAttempt)
  {
     logname=request.getParameter("logname");
     logpass=request.getParameter("logpass");
     logname=getStr(logname);
     logpass=getStr(logpass);
     String sql=("select * from registmessage where logname='"+logname+"'and password='"+logpass+"'");
//out.println(sql);
     ResultSet RS=userBean.executeQuery(sql);
     int rowscount=0;
     try
      {
        while(RS.next())
         { rowscount++; }
      }
      catch(Exception e){}
//out.println(rowscount);
      if(rowscount!=0)
       {
          errorMessage="成功登录";
          session.setAttribute("username",logname);
          loginOK=true;
          if(loginOK){response.sendRedirect("main.jsp");}
        }
          else
           {
              errorMessage="您的用户名或密码错误！";
              session.setAttribute("username","");
           } 

       }
  
 %>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>

<table align="center"border="0"width="101%"cellspacing="0"cellpadding="0"height="355">
  <tr> 
    <td width="1"height="355"bgcolor="#3399ff"></td>
    <td width="758"height="355"valign="top"background="picture/back004.GIF"> <table boder="0"width="100%"cellspacing="0"cellpadding="0"height="451">
        <tr>
		<td colspan="2"height="125"><div id="Layer1" style="position:absolute; width:755px; height:124px; z-index:1; left: 9px; top: 14px;"><img src="picture/024.gif" width="758" height="126"></div></td>
		</tr>
		<tr> 
          <td colspan="2" height="44" bgcolor="#3399ff"> <div align="center"><font color="#000000" size="6"><strong>欢迎进入教师查询系统,请先登录,新用户请先注册</strong></font></div></td>
        </tr>
        <tr> 
          <td colspan="2"height="66"> <div align="center"><font color=red size="6"><%=errorMessage%></font> </div></td>
        </tr>
        <form action=""method="post">
          <tr> 
            <td height="32"width="44%"><div align="right">名字：</div></td>
            <td width="56%"> <input type="hidden"name="returl"value=""> <input type="text" name="logname"value=""> 
            </td>
          </tr>
          <tr> 
            <td align="right"height="32">密码：</td>
            <td> <input type="password"name="logpass"> </td>
          </tr>
          <tr> 
            <td align="center"colspan="2"height="66"><input type="submit"name="login"value="登录">
              |<a href="reg.jsp">注册新用户</a>|</td>
          </tr>
        </form>
        <tr> 
          <td colspan="2" aligh="right">&nbsp;</td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
