首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring 调整servlet

2012-08-22 
spring 整合servletimport java.io.IOExceptionimport javax.servlet.ServletConfigimport javax.servle

spring 整合servlet

import java.io.IOException;import javax.servlet.ServletConfig;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;public class AppServlet extends HttpServlet {    private IAppService appService;    private StoreService storeService;    /**     * @see HttpServlet#HttpServlet()     */    public AppServlet() {        super();    }    /** * 处理get方式请求 */protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {this.doPost(request, response);}/** * 处理post方式请求 */protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {// TODO:解析request中的jsonString jsonStr = "{'ts': 1201226308500,'body':{'user_id':1,'size':5,'device_id':14}}";appService.getRecAppListByUser(jsonStr);storeService.getTest();}@Overridepublic void init(ServletConfig config) throws ServletException {super.init(config);appService = (IAppService)getbean("appService");storeService = (StoreService)getbean("storeService");}private Object getbean(String str){WebApplicationContext wac =WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());return wac.getBean(str);}}

热点排行