在一个使用了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);
- }
- }