package com.mingsoft.servlet;
import java.io.IOException;

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

import org.apache.log4j.Logger;

import com.mingsoft.constant.JspPage;
/**
 * Servlet传递参数和协议的父类
 * @author 成卫雄
 * QQ:330216230
 * 技术支持：景德镇铭飞科技
 * 官网：www.ming-soft.com
 */
@SuppressWarnings("serial")
public class BaseServlet extends HttpServlet {
	//记录日志
	protected Logger log = Logger.getLogger(this.getClass());
	//自动获取项目中文件的路径
	protected static String BASE_URL = "";
	
	//获取项目当前的物理路径
	protected static String BASE_URL_PATH = "";
	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");

		BASE_URL = request.getScheme() + "://" + request.getServerName() + ":"
				+ request.getServerPort() + request.getContextPath()+JspPage.PATH_SYMBOL;
		BASE_URL_PATH = this.getServletContext().getRealPath("")+JspPage.PATH_SYMBOL;
		request.setAttribute("base_url", BASE_URL);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");

		BASE_URL = request.getScheme() + "://" + request.getServerName() + ":"
				+ request.getServerPort() +  request.getContextPath()+JspPage.PATH_SYMBOL;
		BASE_URL_PATH = this.getServletContext().getRealPath(JspPage.PATH_SYMBOL);
		request.setAttribute("base_url", BASE_URL);
	}


}
