`
hunray
  • 浏览: 219344 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

servlet中调用spring的bean

    博客分类:
  • Java
阅读更多
在一个使用了spring的项目中,使用servlet
package com.talkweb.Qmessage.service.servlet;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.talkweb.Qmessage.service.QmessageManager;


public class QmessageServlet extends HttpServlet{

	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
		String message = new String(request.getParameter("content").getBytes("ISO8859-1"));
		//System.out.println(message);
		ServletContext application;   
        WebApplicationContext wac;   
        application = getServletContext();   
        wac = WebApplicationContextUtils.getWebApplicationContext(application);//获取spring的context   
        QmessageManager qmessageManager = (QmessageManager) wac.getBean("QmessageManager");   

        qmessageManager.getGifURL(message);
	}
 
}
分享到:
评论

相关推荐

    SpringBoot学习笔记完整教程

    Spring Boot 学习笔记,包括底层实现原理及...12. Spring boot 普通类调用 Bean 13. spring boot 使用模板引擎 14. Spring boot 集成 JSP 15. Spring boot 集成 servlet 16. Spring boot 集成 Fliter 和 Linstener

    Spring中文帮助文档

    6.8.1. 在Spring中使用AspectJ进行domain object的依赖注入 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7...

    Spring攻略(第二版 中文高清版).part1

    3.7 在你的Bean中引入行为 132 3.7.1 问题 132 3.7.2 解决方案 132 3.7.3 工作原理 132 3.8 为你的Bean引入状态 135 3.8.1 问题 135 3.8.2 解决方案 135 3.8.3 工作原理 135 3.9 用基于XML的配置...

    Spring MVC 入门实例

    11 <bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 12 13 14 <prop key="/hello.do">helloController 15 16 17 </bean> 18 19 <bean id=...

    从零开始学Spring Boot

    1.20 Spring Boot普通类调用bean 1.21 使用模板(thymeleaf-freemarker) 1.22 Spring Boot 添加JSP支持 1.23 Spring Boot Servlet 1.24 Spring Boot过滤器、监听器 1.25 Spring Boot 拦截器HandlerInterceptor 1.26...

    Spring攻略(第二版 中文高清版).part2

    3.7 在你的Bean中引入行为 132 3.7.1 问题 132 3.7.2 解决方案 132 3.7.3 工作原理 132 3.8 为你的Bean引入状态 135 3.8.1 问题 135 3.8.2 解决方案 135 3.8.3 工作原理 135 3.9 用基于XML的配置...

    Spring API

    6.8.1. 在Spring中使用AspectJ进行domain object的依赖注入 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7...

    spring security 参考手册中文版

    12.2.3使用RequestPostProcessor在Spring MVC测试中以用户身份运行 106 作为用户在Spring MVC测试中使用注释运行 108 12.2.4测试HTTP基本认证 109 12.3 SecurityMockMvcRequestBuilders 109 12.3.1测试基于表单的...

    Spring.3.x企业应用开发实战(完整版).part2

    16.7.2 使用Spring Servlet API模拟对象 16.7.3 使用Spring RestTemplate测试 16.7.4 使用Selenium测试 16.8 小结 第17章 实战案例开发 17.1 论坛案例概述 17.1.1 论坛整体功能结构 17.1.2 论坛用例描述 17.1.3 主要...

    ssh(structs,spring,hibernate)框架中的上传下载

     在配置完LobHandler后, 还需要将其注入到sessionFactory的Bean中,下面是调用后的sessionFactory Bean的配置:  代码 6 将lobHandler注入到sessionFactory中的配置 1. 2. … 3. <bean id="sessionFactory" 4. ...

    Spring.html

    Spring IOC 控制反转:把创建对象的权利交给Spring 创建对象 1.无参构造<bean class=""> ... 2....在Servlet中使用WebApplicationContextUtils获取容器对象 5.使用容器对象去获取Service对象

    简单的javaweb在线选课系统(idea使用,版本原因,需要修改些许代码去适应个人的idea配置)

    此《简单的javaweb在线...在新的知识中,还可运用Spring的bean的使用方法,去简化连接数据库,调用数据库的代码冗余,在文件中的applicationContext中可体现出来,在后续的更新中会向大家解释一下Spring基本应用过程。

    spring_MVC源码

    14. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 15. 16. <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 --> 17. <bean class="org....

    Spring面试题

    ☆ Spring AOP:通过配置管理特性,Spring AOP 模块直接将面向方面的编程功能集成到了 Spring 框架中。所以,可以很容易地使 Spring 框架管理的任何对象支持 AOP。Spring AOP 模块为基于 Spring 的应用程序中的对象...

    springboot学习思维笔记.xmind

    web项目设置在Servlet的context parameter中 事件Application Event 自定义事件,集成ApplicationEvent 定义事件监听器,实现ApplicationListener 使用容器发布事件 Spring高级话题 Spring Aware ...

    Spring3.x企业应用开发实战(完整版) part1

    16.7.2 使用Spring Servlet API模拟对象 16.7.3 使用Spring RestTemplate测试 16.7.4 使用Selenium测试 16.8 小结 第17章 实战案例开发 17.1 论坛案例概述 17.1.1 论坛整体功能结构 17.1.2 论坛用例描述 17.1.3 主要...

    Spring Security-3.0.1中文官方文档(翻译版)

    这次发布的Spring Security-3.0.1 是一个bug fix 版,主要是对3.0 中存在的一些问题进 行修 正。文档中没有添加新功能的介绍,但是将之前拼写错误的一些类名进行了修正,建议开发 者以这一版本的文档为参考。 ...

    springboot-web.zip

    拦截器可以获取IOC容器中的各个bean,而过滤器就不行,因为拦截器是spring提供并管理的,spring的功能可以被拦截器使用,在拦截器里注入一个service,可以调用业务逻辑。而过滤器是JavaEE标准,只需依赖servlet api ...

    Spring Security 中文教程.pdf

    5.5. Spring Security中的访问控制(验证) 5.5.1. 安全和AOP建议 5.5.2. 安全对象和AbstractSecurityInterceptor 5.5.2.1. 配置属性是什么? 5.5.2.2. RunAsManager 5.5.2.3. AfterInvocationManager ...

    springmybatis

    查询出列表,也就是返回list, 在我们这个例子中也就是 List<User> , 这种方式返回数据,需要在User.xml 里面配置返回的类型 resultMap, 注意不是 resultType, 而这个resultMap 所对应的应该是我们自己配置的 ...

Global site tag (gtag.js) - Google Analytics