为了账号安全,请及时绑定邮箱和手机立即绑定

为什么写了连接数据库代码 可是注册的时候没有反应???麻烦各位大佬帮忙看一下 感谢!!!

为什么写了连接数据库代码 可是注册的时候没有反应???麻烦各位大佬帮忙看一下 感谢!!!

老子尼克杨 2018-12-20 17:22:39
注册界面的jsp代码:<%@ page language="java" import="java.util.*" contentType="text/html; charset=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>     <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0">     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->     <style>        body{            background: url("./image/loginBG.jpg");            background-repeat: repeat;        }        h1{            text-align: center;            font-family: 楷体;            color: gold;            margin-top: 100px;        }        #DD{            text-align: center;            width: 100%;        }        #XB{            margin-left: -90px;        }    </style>  </head>    <body>    <h1>三井体育</h1><form id="DD" action="zhuceChack.jsp" method="post" onsubmit="return check(this)">    <fieldset>        <legend>注册</legend><br>        用&nbsp;户&nbsp;名:<input type="text" name="uid">        <br><br>        密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" name="upwd" id="st3">        <br><br>        确认密码:<input type="password" id="st4" name="upwd" onblur="check()">        <br><br>        <div id="XB">        性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别:<input type="radio" name="sex" checked="checked">男        <input type="radio" name="sex"/>女        </div>        <br>        联系电话:<input type="text" name="number">        <br><br>        邮箱地址:<input type="email" name="mail" required="required" autofocus="autofocus">        <br><br>        <input type="submit" value="注册" onclick="window.open('login.jsp','_self')">        &nbsp;&nbsp;&nbsp;        <input type="reset" value="重置">        &nbsp;&nbsp;&nbsp;        <input type="button" value="返回" onclick="window.open('login.jsp','_self')">    </fieldset></form><script>    function check() {        var            boo=$('st3').value==$('st4').value;        if(boo){            return true;        }else{            alert('两次密码不一样')        }    }</script>  </body></html>注册界面的beanpackage Bean;public class zhuceBean { private String uid; private String upwd; private String sex; private String number; private String mail; public String getUid() { return uid; } public void setUid(String uid) { this.uid = uid; } public String getUpwd() { return upwd; } public void setUpwd(String upwd) { this.upwd = upwd; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getMail() { return mail; } public void setMail(String mail) { this.mail = mail; } }注册界面连接数据库的代码<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=UTF-8"%><%request.setCharacterEncoding("UTF-8"); %><jsp:useBean id="zhuce" class="Bean.zhuceBean"></jsp:useBean><jsp:setProperty property="*" name="zhuce"/><%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>     <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0">     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->  </head>    <body>    <%    try{    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");    String url = "jdbc:sqlserver://localhost:1433;DatabaseName=sanjin";    String username = "sa";    String password = "yjdi970822";    //创建数据库连接    Connection conn = DriverManager.getConnection(url,username,password);    String sql = "insert into usertab(uid,upwd,sex,number,mail) values(?,?,?,?,?)";//添加信息语句    PreparedStatement ps = conn.prepareStatement(sql);    ps.setString(1,zhuce.getUid());    ps.setString(2,zhuce.getUpwd());    ps.setString(3,zhuce.getSex());    ps.setString(4,zhuce.getNumber());    ps.setString(5,zhuce.getMail());    int row = ps.executeUpdate();    if(row > 0){        out.print("注册成功!!!");     }    ps.close();    conn.close();    }catch(Exception e){        out.print("注册失败!!!");        e.printStackTrace();    }    %>  </body></html>
查看完整描述

1 回答

?
苏凝汐

TA贡献5条经验 获得超0个赞

先把控制台和页面报错信息都贴一下啊。。

查看完整回答
反对 回复 2018-12-21
  • 1 回答
  • 0 关注
  • 704 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信