Requset作用域

案例:当登陆密码或账号不正确时 提示

使用Requset对象中的作用域存储数据

语法:req.setAttribute(key, value);//键值对存在

当密码不存在时,设置作用域

else {
           // resp.sendRedirect("login.jsp");
            req.setAttribute("msg", "账号或密码不正确");
            req.getRequestDispatcher("login.jsp").forward(req,resp );

        }

 在jsp 里面读取

<%
    Object msg = request.getAttribute("msg");
%>
<p style="color: red"><%=msg==null?"":msg%></p>

  

 

原文地址:https://www.cnblogs.com/ww103/p/11955597.html