checkLogin.jsp
上传用户:jhoneliu
上传日期:2022-07-31
资源大小:950k
文件大小:1k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html; charset=GBK" import="java.sql.*" %>
  2. <%
  3. String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
  4. String url = "jdbc:odbc:stud";
  5. String userid="sa",pwd="",sql = "";
  6. try{
  7.   Class.forName(driver);
  8.   Connection conn = DriverManager.getConnection(url,userid,pwd);
  9.   sql = "select * from users where userid='" + request.getParameter("userID") + "' and password='" + request.getParameter("pwd") + "'";
  10.   Statement stmt = conn.createStatement();
  11.   ResultSet rs = stmt.executeQuery(sql);
  12.   if(rs.next())
  13.   {
  14.     session.setAttribute("userid",request.getParameter("userID"));
  15.     response.sendRedirect("memCenter.jsp");
  16.   }
  17.   else
  18.   {
  19. %>
  20. <script language="javascript">
  21. alert("用户名或密码错误");
  22. window.history.go(-1);
  23. </script>
  24. <%
  25.   }
  26. }catch(Exception e)
  27. {
  28.   System.out.println(e.getMessage());
  29. }
  30. %>