(1)生命周期

  ServletContext中的属性的生命周期从创建开始,到服务器关闭而

(2).获取ServletContext

  1、request获取servletContext

    ServletContext servletContext = request.getServletContext();

  2、使用ContextLoader

    ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();

  3、使用spring注入自动注入

    @Autowired

    private ServletContext servletContext;

(3).使用ServletContext存取

  1、添加属性:setAttribute(String name,Object ob);

  2、得到值:   getAttribute(String);    //返回Object

  3、删除属性:removeAttribute(String name);

spring项目获取ServletContext的更多相关文章

  1. spring项目获取ApplicationContext(能手动从Spring获取所需要的bean)

    最流行的方法就是  实现ApplicationContextAware接口 @Component public class SpringContextUtil implements Applicati ...

  2. spring中获取当前项目的真实路径

    总结: 方法1: WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext ...

  3. spring定时器中如何获取servletcontext

    spring定时器中如何获取servletcontext 学习了:https://zhidao.baidu.com/question/406212574.html @Scheduled(cron = ...

  4. spring项目中 通过自定义applicationContext工具类获取到applicationContext上下文对象

    spring项目在服务器启动的时候 spring容器中就已经被创建好了各种对象,在我们需要使用的时候可以进行调用. 工具类代码如下 import org.springframework.beans.B ...

  5. java类中获取ServletContext的方法

    起因是我想要获取一个相对路径,需要用到servletContext的getRealPath()方法,于是上网搜索,找到两种方法来获取ServletContext. 方法1:第一种方法是这样的: Ser ...

  6. 建立一个Hello World级别的Spring项目

    package com.sevenhu.domain; import org.springframework.context.ApplicationContext; import org.spring ...

  7. 【工具】Spring项目转化Spring Web项目插件

    前言 源于前一篇博文中提到,将Spring项目转化为Spring Web项目,发现添加项目文件和修改pom.xml文件等都是手动完成的,心想着开发一个Idea插件来自动化完成上面的过程,实现一键转化. ...

  8. spring项目读取配置文件

    Spring项目在运用中读取配置文件有两种方式: 通过项目的配置文件读取 在spring-context.xml里面加入以下代码 在运用到的类里面加入 @Value("#{configPro ...

  9. Spring入门(一):创建Spring项目

    本篇博客作为Spring入门系列的第一篇博客,不会讲解什么是Spring以及Spring的发展史这些太理论的东西,主要讲解下如何使用IntelliJ IDEA创建第一个Spring项目以及通过一个示例 ...

随机推荐

  1. JS中多维数组的深拷贝的多种实现方式

    因为javascript分原始类型与引用类型(与java.c#类似).Array是引用类型,所以直接用=号赋值的话,只是把源数组的地址(或叫指针)赋值给目的数组,并没有实现数组的数据的拷贝.另外对一维 ...

  2. 9.indicate、xutils、json

    json数据  页签详情页数据   public class TabData { public int retcode; public TabDetail data;//不是数组的话类型就是这个 pu ...

  3. 为什么 echo 3 . print(2) . print(4) . 5 . 'c'的结果是45c2131

    例子:请写出echo 3 . print(2) . print(4) . 5 . 'c'的输出结果为____? 许多人看到这个题的第一印象是输出结果不就是3245c嘛,然而正确的是答案却是45c213 ...

  4. Swift5 语言指南(一) 关于Swift

    Swift是编写软件的绝佳方式,无论是用于手机,台式机,服务器还是其他任何运行代码的软件.它是一种安全,快速,交互式的编程语言,它将现代语言思维的最佳结合与来自更广泛的Apple工程文化的智慧和来自开 ...

  5. Python 基础:分分钟入门

    Python和Pythonic Python是一门计算机语言(这不是废话么),简单易学,上手容易,深入有一定困难.为了逼格,还是给你们堆一些名词吧:动态语言.解释型.网络爬虫.数据处理.机器学习.We ...

  6. B - Red and Black 问题思考

    红黑地板问题 There is a rectangular room, covered with square tiles. Each tile is colored either red or bl ...

  7. ubuntu16.04 编译出错:fatal error: SDL/SDL.h: No such file or directory

    在ubuntu 16.04编译神经网络代码时候,遇到了这样一种错误? fatal error: SDL/SDL.h: No such file or directory 原因是SDL库没有安装,根据你 ...

  8. Ehcache3开发入门简介

    在高并发应用中缓存就是核心机制.最近在研究Ehcache,发现这是一个更加灵活易用的缓存框架(相对于Redis.Memcache),Ehcache更加小巧轻便.而且都有持久化机制,不用担心JVM和服务 ...

  9. Centos 7 Asp.net core 使用QRCoder 报“Unable to load DLL 'gdiplus'"

    环境: Centos7 .Net core 2.0 问题: 使用QRCoder 报“Unable to load DLL 'gdiplus'" 同 https://q.cnblogs.com ...

  10. Docker: connection reset by peer

    想来,对docker的学习和实践,已经一年有余了,而我关于这样的文章,只有为数不多的几篇.今天借使用docker中发生的一种异常情况为例,写此篇幅. 这个是在centos7.0 ..netcore2. ...