09

<%@page import="com.gd.dao.UsersDao"%>
<%@page import="com.gd.entity.Msg"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
   <%
        
            // 接收参数
            String email = request.getParameter("email");
            String name = request.getParameter("name");
            String pwd = request.getParameter("pwd");
            UsersDao ud = new UsersDao();
            ud.zc(name, pwd, email);
            request.getRequestDispatcher("index.jsp").forward(request, response);
            
   %>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>注册</title>
</head>
<body>
 <center>


        <form action="dozhuce.jsp" method="post">
            <table>
                <tr>
                   <h3> 注册信息:</h3>
                </tr>
            
                <tr>
                    <td>用户名:</td>
                    <td><input type="text" name="name"></td>
                 
                </tr>               
                <tr>
                    <td>密码:</td>
                    <td><input type="text" name="pwd"></td>
                </tr>
                  <tr>
                    <td>邮箱:</td>
                    <td><input type="email" name="email"></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" value="注册">
                        <input type="reset" value="重置">
                    </td>
                </tr>
            </table>
        </form>
        <h3><a href="index.jsp">回到登陆首页</a></h3>

        <hr>
</center>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>登录</title>
    
    
    <link rel="stylesheet"  href="style/css.css">

    <script type="text/javascript">
    function mycheck(){
    if(form1.uname.value==""){
    alert("用户名不能为空,请输入用户名");
    form1.uname.focus();
    return;
    }
    if(form1.upwd.value==""){
    alert("密码不能为空,请输入密码");
    form1.upwd.focus();
    return;
    }
    if(form1.validationCode.value==""){
    alert("验证码不能为空,请输入验证码");
    form1.validationCode.focus();
    return;
    }
    if(form1.validationCode.value!=form1.validationCode1.value){
    alert("请输入正确的验证码");
    form1.validationCode.focus();
    return;
    }
    form1.submit1();
    }
    </script>
  </head>
  
  <body>
  <center>
   <form action="dologin.jsp" name="form1" method="post"  >
   <table width="50%">
                <tr>
                    <td colspan="2"><STRONG style="color:red;font-size:30px;">      用户登陆</STRONG></td>
                </tr>
                 <tr>
                    <td>用户名:</td>
                    <td><input type="text" name="uname" value="小白" /></td>
                  </tr>
                   <tr>
                    <td>&nbsp;&nbsp;码:</td>
                    <td><input type="password" name="upwd" value="88888"/></td>
                   </tr>
                 <tr>
                   <td>
                        验证码:
                   </td>
            <td> <input type="text" name="validationCode" onKeyDown="if(event.keyCode==13){form1.submit.focus();}"size="6">
              <%
              int intmethod1=(int)((((Math.random())*11))-1);
              int intmethod2=(int)((((Math.random())*11))-1);
              int intmethod3=(int)((((Math.random())*11))-1);
              int intmethod4=(int)((((Math.random())*11))-1);
              
               String intsum=intmethod1+""+intmethod2+intmethod3+intmethod4;
               %> 
               <input type="hidden" name="validationCode1" value="<%=intsum%>">
               <img style="height:20px;weight:20px" src="images/<%=intmethod1 %>.png">
               <img style="height:20px;weight:20px" src="images/<%=intmethod2 %>.png">
               <img style="height:20px;weight:20px" src="images/<%=intmethod3 %>.png">
               <img style="height:20px;weight:20px" src="images/<%=intmethod4 %>.png">
               </td>
                  <tr>
                    <td colspan="2">
                      <input type="submit"  name="submit1" value="登录" onClick="mycheck()">
                      <input type="reset" value="重置">
                      <a href="zhuce.jsp"><input type="button" value="注册"></a>
                    </td>
                </tr>
            </table>
</form>
</center>
  </body>
</html>
//注册功能
    
    public boolean zc(String name, String pwd,String email) throws SQLException {
        // 获取连接
        Connection conn = getConnection();
        // 编写sql语句
         String sql = "INSERT INTO users(username,password,email) values (?,?,?)";
            
        // 执行sql语句
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, name);
        ps.setString(2, pwd);
        ps.setString(3, email);
        ps.executeUpdate();
        closeAll(conn, ps, null);
        return false;
    }

posted @ 2020-05-16 16:56  1014040868a  阅读(101)  评论(0编辑  收藏  举报