问答详情
源自:4-11 阶段案例——实现用户登录

用户名和密码都是admin为什么登录不成功

login.jsp;

<body>

  <div id="box1">

  </div>

    <div id="box">

    <form action="dologin.jsp" method="post">

    <p class="main">

    <label>用户名:</label>

    <input name="username" value="" > 

    <label>密码:</label>

    <input type="password" name="password" value="">

    </p>

    <p class="space">

    <input type="submit" value="登录" class="login" style="cursor:pointer;">

    </p>

    </form>

    </div>

  </body>



login_failure.jsp

<body>

    <div id="box">

    登录失败,请检查您的用户名或者密码<br>

    <a href="login.jsp">返回登录</a>

    </div>

  </body>



login_success.jsp

 <div id="box">

    <%

    String loginUser="";

    if(session.getAttribute("loginUser")!=null){

    loginUser=session.getAttribute("loginUser").toString();

    }

    %>

    欢迎<font color="red"><%=loginUser %></font>,登录成功

    </div>



dologin.jsp

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String username="";

String password="";

request.setCharacterEncoding("utf-8");


username=request.getParameter("username");

password=request.getParameter("pasword");


if("admin".equals(username) && "admin".equals(password)){

session.setAttribute("loginUser",username);

request.getRequestDispatcher("login_success.jsp").forward(request,response);

}else{

response.sendRedirect("login_failure.jsp");

}

%>


提问者:慕数据612857 2017-08-12 09:56

个回答

  • 锵域
    2017-08-12 10:42:44
    已采纳

    dologin.jsp里面的《password=request.getParameter("pasword");》“pasword”是不是少了一个“s”。