⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 initservlet.java

📁 这是一个用java三层框架做的ISS学员管理系统
💻 JAVA
字号:
package com.isoftstone.isscrmweb.web.common;

import java.io.File;

import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.isoftstone.isscrmweb.web.advice.AutoLogAdvice;

/**
 * Created by IntelliJ IDEA.
 * User: Songzou
 * Date: 2007-4-8
 * Time: 10:35:31
 *
 * 系统初始化参数servlet
 */
public class InitServlet extends HttpServlet {

    /**
	 * 
	 */
	private static final Log log = LogFactory.getLog(InitServlet.class); 
	
	private static final long serialVersionUID = 6066089839055144264L;

	public void init(ServletConfig servletConfig) throws ServletException {
		log.info("正在执行初始化配置......");
		String filepath = servletConfig.getInitParameter("configLocation");	
		ServletContext context = servletConfig.getServletContext();
		filepath =  context.getRealPath("") + filepath ;
		File file = new File(filepath);
		if(file.exists()){
			log.info("已经找到初始化配置文件:"+file.getAbsolutePath());
			try{
				SAXReader reader = new SAXReader();
				Document doc = reader.read(file);
		        Element root = doc.getRootElement();
		        String systemName = root.element("systemName").elementTextTrim("value");
		        String email = root.element("manager-email").elementTextTrim("value");
		        String autoLog = root.element("autoLog").elementText("value");
		        String checkCodeString = root.element("charRandomCode").elementText("value");
		        Boolean checkCode = false ;
		        try{
		        	checkCode = Boolean.parseBoolean(checkCodeString);
		        }catch(Exception e){}
		        try{
		        	AutoLogAdvice.autoLog=Boolean.parseBoolean(autoLog);
		        }catch(Exception e){}
		        log.info("自动日志状态:"+AutoLogAdvice.autoLog);
		        log.info("开启验证码登陆状态:"+checkCode);
		        log.info("管理员邮箱:"+email);
		        log.info("系统名称:"+systemName);
		        context.setAttribute("randomCheckCode",checkCode);
		        context.setAttribute("manager-email", email);
		        context.setAttribute("systemName",systemName);
		        log.info("系统初始化配置已完成!");
			}catch(Exception e){
				e.printStackTrace();
				throw new ServletException("Init exception cause by "+file.getAbsolutePath());
			}	
		}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -