求解释:
request.getSession().setAttribute("USER", USER);
和
request.getSession().getServletContext().setAttribute("USER", USER);
有什么异同???
(USER是封装了用户信息的一个对象)
request.getSession().setAttribute("USER", USER);
和
request.getSession().getServletContext().setAttribute("USER", USER);
有什么异同???
(USER是封装了用户信息的一个对象)
page,request,seesion,applicationrequest.getSession().setAttribute("USER", USER);
这个就是把属性值放到session中,比如单个用户信息request.getSession().getServletContext().setAttribute("USER", USER);
这个就是把属性值放到application中,比如网站登录人数
形象点说吧,这几个对象就是一个个容器,你可以理解为request最小,session大一点,servletcontext最大,request一次请求完毕就没了,session给某一个特定的对象来用,取出其中的属性值来了可能数据信息还留着,等要用的时候,该对象再调就又能用了,servletcontext就更大了,整个web应用谁都拿到里面的属性值。你现在该能知道request.setAttribute("USER", USER); request.getSession.setAttribute("USER", USER);request.getSession.getServletContext.setAttribute("USER", USER);的区别了吧