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

xiaoxiao2022-06-14  29

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

 }

转载请注明原文地址: https://www.6miu.com/read-4936711.html

最新回复(0)