首页 > 其他 > 详细

ServletContext与三大作用域对象

时间:2020-09-11 16:29:25      阅读:47      评论:0      收藏:0      [点我收藏+]

ServletContext(Servlet上下文对象),是web应用全局对象。

一个Web应用只会创建一个ServletContext对象

Java Web 三大作用域对象

HttpServletRequest - 请求对象

HttpSession - 用户会话对象

ServletContext - web应用全局对象

 

ServletContext context = request.getServletContext();
context.setAttribute("content", "© 2020 imooc.com 京ICP备 12003892号-11");
context.setAttribute("title", "<h1>幕课网</h1>");

response.setContentType("text/html;charset=utf-8");

response.getWriter().println("ServletContext 学习");

 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

ServletContext context = request.getServletContext();
String name = (String)context.getAttribute("content");
String title = (String)context.getAttribute("title");

response.setContentType("text/html;charset=utf-8");

response.getWriter().println("<h1>"+name+"</h1>"+title);

  

  

  

ServletContext与三大作用域对象

原文:https://www.cnblogs.com/wuheng-123/p/13651706.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!