public class Log4jInit extends HttpServlet { private static final String CONTENT_TYPE = "text/html; charset=GBK"; public static Logger logger = Logger.getLogger(Log4jInit.class.getName());
//Initialize global variables public void init() throws ServletException { //通過web.xml來動態(tài)取得配置文件 String prefix = getServletContext().getRealPath("/"); String file = getInitParameter("log4j-init-file"); // 如果沒有給出相應的配置文件,則不進行初始化 if (file != null) { PropertyConfigurator.configure(prefix + file); } }
public void doGet(HttpServletRequest req, HttpServletResponse res) { }