在Servlet中获取业务层service对象的方法

public class AjaxProcess extends HttpServlet {
 
 private AnalyzeproductService pService;
 private AnalyzeorderService orderService;

 public AjaxProcess() {
  super();
 }

 public void destroy() {
  super.destroy();
 }

 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  doPost(request, response);
 }

 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  response.setContentType("text/html");
  response.setCharacterEncoding("gb2312");
  PrintWriter out = response.getWriter();
  String method=request.getParameter("method");
  //生成编号
  if("getNumber".equals(method)){
   String number=orderService.createNumber();
   out.println(number);
   
  }
 }


 public void init() throws ServletException {
    super.init();
    pService = (AnalyzeproductService) WebApplicationContextUtils
     .getRequiredWebApplicationContext(getServletContext())
     .getBean("analproductService");
    orderService=(AnalyzeorderService) WebApplicationContextUtils
     .getRequiredWebApplicationContext(getServletContext())
     .getBean("analyzeorderService");

 }

你可能感兴趣的:(Other,Servlet,HTML)