zoukankan      html  css  js  c++  java
  • ServletContext与三大作用域对象

    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);

      

      

      

  • 相关阅读:
    证书格式转换
    emq知识点
    emq共享订阅
    SpringBoot
    Android网络编程Socket长连接
    Android 网络通信框架Volley简介(Google IO 2013)
    Android中的5种数据存储方式
    Android
    android解析XML总结(SAX、Pull、Dom三种方式)
    乔迁新禧
  • 原文地址:https://www.cnblogs.com/wuheng-123/p/13651706.html
Copyright © 2011-2022 走看看