您的位置:首页 > 编程语言 > Java开发

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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: