Package com.lgx8.gateway.member.servlet

Source Code of com.lgx8.gateway.member.servlet.CheckCardExistsServlet

package com.lgx8.gateway.member.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.lgx8.gateway.dao.ICardDao;
import com.lgx8.right.dao.IUserDao;

/**
* Servlet implementation class CheckCardExistsServlet
*/
public class CheckCardExistsServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckCardExistsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
  }

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   
    Integer count = Integer.parseInt(request.getParameter("count"));
    String card = request.getParameter("card");
    String mobile = request.getParameter("mobile");
   
    long car3 = Long.parseLong(card);
   
    Boolean flag = false;
   
    ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    ICardDao cardDao = (ICardDao) ac.getBean("cardDao");
   
    for(int i=1;i<=count;i++,car3++)
    {
      //生成卡号且卡号唯一
      String car = car3 + "";
     
      flag = cardDao.checkCardExists(car.toUpperCase());
     
      if(flag) break;
     
    }
   
    String str = "";
   
    if(count == 1 &&(mobile != null && !"".equals(mobile)))
    {
      IUserDao userDao = (IUserDao) ac.getBean("userDao");
      str = userDao.checkMobileExists(mobile);
    }
   
    try {
      PrintWriter out = response.getWriter();
      if(flag)
      {
        if("0".equals(str))
        {
          out.println("3");
        }else if("1".equals(str))
        {
          out.println("2");
        }
      }
      else
      {
        if("0".equals(str))
        {
          out.println("1");
        }else if("1".equals(str))
        {
          out.println("0");
        }
      }
           out.flush();
           out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}
TOP

Related Classes of com.lgx8.gateway.member.servlet.CheckCardExistsServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.