與mysql,判斷能否登入帳號密碼

來源:互聯網
上載者:User

標籤:driver   param   manage   har   character   tle   check   password   sql   

  1. <%@ page language="java" import="java.sql.*" contentType="text/html;charset=utf-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  7. <html>  
  8.   <head>  
  9.     <base href="<%=basePath%>">  
  10.     <title>My JSP ‘check.jsp‘ starting page</title>  
  11.     <meta http-equiv="pragma" content="no-cache">  
  12.     <meta http-equiv="cache-control" content="no-cache">  
  13.     <meta http-equiv="expires" content="0">      
  14.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  15.     <meta http-equiv="description" content="This is my page">  
  16.     <!--  
  17.     <link rel="stylesheet" type="text/css" href="styles.css">  
  18.     -->  
  19.  </head>  
  20.   <body>  
  21. <%  
  22.    request.setCharacterEncoding("utf-8");  
  23.    String users=request.getParameter("username");  
  24.    String pass=request.getParameter("pwd");  
  25.    boolean flag=false;  
  26.    PreparedStatement sql=null;    
  27.    ResultSet rs=null;  
  28.    Connection conn=null;  
  29. %>  
  30.   
  31. <%   
  32.     String driver = "com.mysql.jdbc.Driver";    
  33.     String url = "jdbc:mysql://127.0.0.1:3307/login";    
  34.     String use = "root";     
  35.     String password = "960404";    
  36.     Class.forName(driver);    
  37.     conn= DriverManager.getConnection(url,use,password);    
  38.     sql =conn.prepareStatement("select * from student where username=? and password=?");  
  39.     sql.setString(1,users);  
  40.     sql.setString(2,pass);  
  41.     rs=sql.executeQuery();  
  42.     if (rs.next()) {    
  43.     flag=true;  
  44.      }  
  45.    rs.close();  
  46.    sql.close();  
  47.    conn.close();  
  48.   %>  
  49. <!-- 判斷是否是正確的登入使用者 -->  
  50. <% if (flag==true){ %>  
  51. <jsp:forward page="show.jsp"/>  
  52. <%}   
  53. else  
  54. if (flag==false){  
  55. %>  
  56. <jsp:forward page="login_fali.jsp"/>  
  57. <%} %>  
  58. </body>  
  59. </html> 

與mysql,判斷能否登入帳號密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.