在用户登录页面,服务器返回的消息,如“用户不存在”等在jsp页面不显示在服务器端登录代码中,“用户名不存在”“密码错误”信息是用setAttribute来存储的,                 //根据查询结果来判断是否允许用户的登陆操作
if(emp == null){//判断用户名是否存在
request.setAttribute("Error", "用户名不存在");
return flag;
}else if(!emp.getPassword().equals(password)){
// 判断密码是否一致
request.setAttribute("Error", "密码错误");
return flag;
在login.jsp登录页面中:
          <tr>
<td colspan="3" align="center"><% String info = (String) request.getAttribute("Error"); 
if(info!=null){
out.println("<span style='font-size:20px;color:red'>"+info+"</span>");
}%>
        </td>
</tr>提示错误时,页面不显示。

解决方案 »

  1.   

    看你跳转画面的方式是forward还是redirect,如果是redirect就拿不到request的值
      

  2.   

    //控制登陆
    if (action.equals("/login")) {
    LoginAction lg = new LoginAction();
    try {
    if (lg.doPost(request, response)) {
    request.getRequestDispatcher("main.jsp").forward(request,response);
    } else {
    response.sendRedirect("login.jsp");
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }我用的是sendRedirect.
      

  3.   


    我用的是if语句来判断,如果成功,就forward到登录后的界面,失败的话,就返回到登录界面。请问怎么修改?
      

  4.   

    这个要不改成转发,不要用重定向,或者把错误信息放到session里面
      

  5.   

    else语句中怎么写?
    request.getRequestDispatcher("login.jsp").forward(request,response);
    这样写对吗?