判断用户注册的帐号能否注册

  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.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>检验注册页面</title>  
  13.     <meta http-equiv="pragma" content="no-cache">  
  14.     <meta http-equiv="cache-control" content="no-cache">  
  15.     <meta http-equiv="expires" content="0">      
  16.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  17.     <meta http-equiv="description" content="This is my page">  
  18.     <!--  
  19.     <link rel="stylesheet" type="text/css" href="styles.css">  
  20.     -->  
  21.   
  22.   </head>  
  23.     
  24.   <body>  
  25.     <br>  
  26.    <%  
  27.    request.setCharacterEncoding("utf-8");  
  28.    String users=request.getParameter("username");  
  29.    String pass=request.getParameter("pwd");  
  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.     Connection conn= DriverManager.getConnection(url,use,password);    
  38.     PreparedStatement sql =conn.prepareStatement("insert into student(username,password)values(?,?)");  
  39.     sql.setString(1,users);  
  40.     sql.setString(2,pass);   
  41.     int rtn=sql.executeUpdate();  
  42.     sql.close();  
  43.     conn.close();  
  44.     %>  
  45.       
  46.   </body>  
  47. </html> 
posted @ 2017-11-29 22:51  can丶  阅读(287)  评论(0编辑  收藏  举报