package com.lgx8.common.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.common.entities.IPObject;
import com.lgx8.common.util.Escape;
import com.lgx8.gateway.service.IGatewayService;
/**
* Servlet implementation class InitCityServlet
*/
public class InitCityServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public InitCityServlet() {
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 {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String areaName = Escape.unescape(request.getParameter("areaName")).trim();
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
IPObject iPObject = gatewayService.findIPObjectByAreaName(areaName);
if(iPObject != null)
{
request.getSession().setAttribute("iPObject", iPObject);
}else
{
iPObject = gatewayService.findIPObjectByAreaName("长沙市");
request.getSession().setAttribute("iPObject", iPObject);
areaName = "长沙市";
}
request.getSession().setAttribute("areaName", areaName);
System.out.println(request.getSession().getAttribute("areaName"));
}
}