保存数据的对象作用于从大到小:

  ServletContext  --  保存数据到web项目中

  Session(会话对象)  --  

  Request     --  保存当前请求(链),有转发就保存包括转发的数据

  PageContext     --  保存到当前(JSP)页面中.  

常用Session和Request

  1.ServletContext 

   //获取servletContext对象,存储数据

   getServletContext().setAttribute("name","rose");  

   //获取数据

   getServletContext().getAttribute("name");

   //获取页面单条数


  2.  Session(会话对象)

  3.  Request

 

    //以键值对存储数据

    

    //读取数据

    request.getAttribute("name");

 4.  PageContext
    //存数据
    pageContext.setAttribute("name","jerry");
    //取数值
    pageContext.getAttribute("name");


JSP页面存数据
Web_Servlet四大域对象

 

 JSP页面取值

 Web_Servlet四大域对象

 

pageContext.findAttribute("key");

 表示从页面中寻找键为key的值,顺序是按域的作用范围从小到大寻找

 

 

 






相关文章:

  • 2021-11-19
  • 2021-11-19
  • 2021-11-19
  • 2021-11-19
  • 2021-11-19
  • 2022-02-02
  • 2021-04-06
猜你喜欢
  • 2021-11-19
  • 2021-11-19
  • 2021-11-19
  • 2022-12-23
  • 2021-11-19
  • 2021-04-18
  • 2021-11-19
相关资源
相似解决方案