ServletConfig       config.getServletContext();

GenericServlet      this.getServletContext();

HttpSession         getServletContext()

ServletContextEvent getServletContext()

struts2中

1.ServletActionContext类

public String rsa() throws Exception{

HttpServletRequest request = ServletActionContext.getRequest();

ServletContext servletContext = ServletActionContext.getServletContext();

request.getSession()

HttpServletResponse response = ServletActionContext.getResponse();

return "scope";

}

2. 实现指定接口,由struts框架运行时注入

public class HelloWorldAction implements ServletRequestAware, ServletResponseAware, ServletContextAware{

private HttpServletRequest request;

private ServletContext servletContext;

private HttpServletResponse response;

public void setServletRequest(HttpServletRequest req) {

this.request=req;

}

public void setServletResponse(HttpServletResponse res) {

this.response=res;

}

public void setServletContext(ServletContext ser) {

this.servletContext=ser;

}

}

获取ServletContext的更多相关文章

  1. java中获取ServletContext常见方法

    http://blog.sina.com.cn/s/blog_3fe961ae0100wjnf.html 1.在javax.servlet.Filter中直接获取 ServletContext con ...

  2. 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法

    今天遇到了一个在servlet的service方法中获取ServletContext对象出现java.lang.NullPointerException(空指针)异常,代码如下: 1 //获取Serv ...

  3. springMvc获取servletContext

    springMvc获取servletContext WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebA ...

  4. java类中获取ServletContext的方法

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

  5. spring项目获取ServletContext

    (1)生命周期 ServletContext中的属性的生命周期从创建开始,到服务器关闭而 (2).获取ServletContext 1.request获取servletContext ServletC ...

  6. struts2获取ServletContext对象

      CreateTime--2017年9月7日09:24:40 Author:Marydon struts2获取ServletContext对象 需要导入: import javax.servlet. ...

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

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

  8. 使用shiro安全框架上传文件时用HttpSession获取ServletContext为null问题解决方法。

    <!--在shiroFilter 中加入一下配置--> <init-param> <param-name>targetFilterLifecycle</par ...

  9. Java中获取ServletContext的方法

    Servlet: this.getServletContext() this.getServletConfig().getServletContext() request.getSession().g ...

随机推荐

  1. 引用计数gc机制使用不当导致内存泄漏

    上一篇文章找同事review了一下,收到的反馈是铺垫太长了,我尽量直入正题,哈哈 最近dbd压测时发现内存泄漏,其实这个问题去年已经暴露了,参见这篇博客[压测周].当时排查不够仔细,在此检讨下.关于d ...

  2. 判断表字段是否存在default约束

    sql语句 IF NOT EXISTS ( SELECT * FROM dbo.syscolumns WHERE id = OBJECT_ID('[dbo].[TActScoreReceiveRec] ...

  3. 【转】AngularJS 取消对 HTML 片段的转义

    今天尝试用 Rails 做后端提供 JSON 格式的数据, AngularJS 做前端处理 JSON 数据,其中碰到 AngularJS 获取的是一段 HTML 文本,如果直接使用 data-ng-b ...

  4. HTTP协议详解--转载http://blog.csdn.net/gueter/article/details/1524447

    引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...

  5. 查杀 oracle sql 卡死的进程

    --查出SID名字select * from v$access where object ='PKG_SMSSEND_PROC';--通过sid查出spidselect  spid,osuser, s ...

  6. SQL总结(四)编辑类

    SQL总结(四)编辑类 应有尽有 1.数据库 创建数据库语法: CREATE DATABASE database_name 1)创建测试库 CREATE DATABASE TestDB 2)使用库 U ...

  7. [Java] - 格式字符串替换方法

    Java 字符串格式替换方法有两种,一种是使用String.format(...),另一种是使用MessageFormat.format(...) 如下: import java.text.Messa ...

  8. JSONP理解和使用

    一.代码使用: $.ajax({ async:false, url: http://跨域的dns, type: "GET", dataType: 'jsonp'}); 二.理解: ...

  9. Swagger使用总结

    Swagger使用总结 1. Swagger是什么? 官方说法:Swagger是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作 ...

  10. android学习笔记57——Service_2

    Service生命周期 参考:http://codingnow.cn/android/515.html 应用程序启动服务的方式不同,其生命周期也有所不同. startService生命周期如下左图: ...