快捷导航

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

部分代码:
        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.class),username,password);
        }


控制台输出结果
111111111111
十二月 31, 2017 2:00:59 上午 com.mchange.v2.log.MLog
信息: 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登陆失败



免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

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

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP