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>

  

 

 

posted @ 2019-11-29 08:47  wu110111‬  阅读(126)  评论(0编辑  收藏  举报