当前位置: 代码迷 >> Java Web开发 >> JSP 用户名密码传值异常,帮忙看上。
  详细解决方案

JSP 用户名密码传值异常,帮忙看上。

热度:7690   发布时间:2013-02-25 21:13:42.0
JSP 用户名密码传值错误,帮忙看下。。~~
articleFlat.jsp
Java code
<form action="checklogin.jsp" method="post">                        <input type="hidden" name="action" value="login" />                        <div class="fastlg cl">                            <div class="y pns">                                <table cellspacing="0" cellpadding="0">                                    <tbody>                                        <tr>                                            <td>                                                <label for="username">                                                    用户名                                                </label>                                            </td>                                            <td>                                                <input type="text" name="username" />                                            </td>                                            <td class="fastlg_l">                                                <label for="ls_cookietime">                                                    <input type="checkbox" name="cookietime" id="ls_cookietime"                                                        class="pc" value="2592000" tabindex="903">                                                    自动登录                                                </label>                                            </td>                                        </tr>                                        <tr>                                            <td>                                                <label>                                                    <label for="password">                                                          密码                                                    </label>                                                </label>                                            </td>                                            <td>                                                <input type="password" name="password" />                                            </td>                                            <td class="fastlg_l">                                                <button type="submit" class="pn pnc vm" tabindex="904">                                                    <em>登录</em>                                                </button>                                            </td>                                            <td class="cl">                                                <a href="register.jsp" class="reglink xi2 xw1"><span>立即注册</span>                                                </a>                                            </td>                                        </tr>                                    </tbody>                                </table>                                <input type="hidden" name="quickforward" value="yes">                                <input type="hidden" name="handlekey" value="ls">                            </div>                        </div>                    </form>


checklogin.jsp
Java code
<%    String action = request.getParameter("action");    String userId = new String(request.getParameter("username"));    String password1 = new String(request.getParameter("password"));System.out.println(action+" "+userId+" "+password1);    Class.forName("com.mysql.jdbc.Driver");    Connection con = DriverManager.getConnection(            "jdbc:mysql://localhost:3306/bbs", "root", "admin");    Statement stmt = con.createStatement();    String sql = "select * from user where user = '" + userId + "';";    System.out.println(sql);    ResultSet rs = stmt.executeQuery(sql);    if (rs.next()) {        String password = new String(rs.getString("password"));        if (password.equals(password1)) {            session.setAttribute("userId", userId);            System.out.println("登陆成功");            response.sendRedirect("complete.jsp");        } else {            response.sendRedirect("articleFlat.jsp");        }    }else {        response.sendRedirect("articleFlat.jsp");    }%>
  相关解决方案