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

jsp+servlet+jdbc简单的登陆操作,却没有报错也没有登录成功

jsp+servlet+jdbc简单的登陆操作,却没有报错也没有登录成功

慕粉3505864 2017-12-31 01:59:29
部分代码: public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 1.字符处理 request.setCharacterEncoding("utf8"); response.setCharacterEncoding("utf8"); response.setHeader("content-type", "text/html;charset=utf8"); // 3. 获得保存在session的验证码 HttpSession session = request.getSession(); // 4.获取打印类 PrintWriter out = response.getWriter(); // 5.获取验证码,判断验证码是否正确 String randCode = request.getParameter("code"); String rand = session.getAttribute("IdentifyCode").toString(); if (randCode != null && !randCode.trim().equals("")) { if (!randCode.trim().equals(rand)) {// 验证码不通过 out.write("CodeFalse"); return; } // 接收前端传进来的账号和密码 // 接收数据 // 1.得到请求参数 String username = request.getParameter("username"); String password = request.getParameter("password"); System.out.println(username+password); // 2.登录 UserService service = new UserService(); try { User user = service.login(username, password); if (user != null) {// 登陆成功 out.write("LoginSuc"); return; } else { System.out.println("LoginServlet登陆失败"); out.write("LoginFail"); return; } } catch (Exception e) { e.printStackTrace(); System.out.println("LoginServlet登陆失败"); out.write("LoginFail"); } } }UserDao的代码 public User login(String username, String password) throws SQLException { String sql = "select * from user where username=? and password=?"; QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); return runner.query(sql, new BeanHandler<User>(User.class),username,password); }控制台输出结果111111111111十二月 31, 2017 2:00:59 上午 com.mchange.v2.log.MLog <clinit>信息: MLog clients using java 1.4+ standard logging.十二月 31, 2017 2:01:00 上午 com.mchange.v2.c3p0.C3P0Registry banner信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]十二月 31, 2017 2:01:01 上午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1bqzwb29s1arxty7eq2dop|40634bec, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1bqzwb29s1arxty7eq2dop|40634bec, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql:///chatroom, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]LoginServlet登陆失败 
查看完整描述

2 回答

?
慕粉3505864

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

查看了一下user 返回的是null值,这是为什么?排除密码或用户名查询的时候匹配不上这个可能

查看完整回答
反对 回复 2017-12-31
  • 2 回答
  • 0 关注
  • 1406 浏览

添加回答

举报

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