servlet中调用spring的bean
2013-04-26 09:11
453 查看
在一个使用了spring的项目中,使用servlet
Java代码
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);
}
}
Java代码
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);
}
}
相关文章推荐
- 在Servlet中直接调用Spring的getBean引起的HTTP Status 500 - Incorrect result size: expected 1, actual 0异常
- servlet调用spring容器中的bean,的两种方式一种注解一种xml配置
- servlet调用spring容器中的bean,的两种方式一种注解一种xml配置
- servlet调用spring中的bean(注解方式)
- 如何让servelt和Filter注入到spring容器或者在servlet中调用spring中的bean
- 解决servlet调用spring中bean的问题
- 在Servlet中调用spring中定义的Bean
- Servlet中调用Spring管理的Bean
- 解决servlet调用spring中bean的问题
- servlet调用spring容器中的bean,的两种方式一种注解一种xml配置
- spring和gwt整合,让gwt直接调用spring bean的前端servlet
- Spring 全注解配置 bean 和 调用 (9) 5种通知
- spring aop 同一个bean中方法调用方法
- Spring的XML配置的bean调用注解方式的bean
- spring mvc示例_servlet获取spring Bean
- web启动,quartz 关联的servlet 启动,得到Spring的bean ,servletContext 获取数据源
- Spring管理filter和servlet,无硬编码bean
- 如何使用spring的autowire为servlet注入Bean
- spring-servlet.xml 和 application.xml 配置含义及bean被加载两次的问题
- java类和servlet中访问spring中的bean