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

📄 initializationservlet.java

📁 基于struts框架的web开发应用实例
💻 JAVA
字号:
/*
 * Created on Mar 22, 2004
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package com.hp.mw.samples.struts.storefront.servlets;

import java.sql.SQLException;
import java.util.Enumeration;

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

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hp.mw.samples.struts.storefront.datasources.ConfigurableDataSource;
import com.hp.mw.samples.struts.storefront.utils.StringUtils;

/**
 * @author zcollier
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class InitializationServlet extends HttpServlet {
	
  /**
    * Default value for <code>serialVersionUID</code> required for Serializable class
    */
   private static final long serialVersionUID = 1L;

   private static Log logger = LogFactory.getLog(InitializationServlet.class);

	/* (non-Javadoc)
	 * @see javax.servlet.GenericServlet#init()
	 */
	public void init() throws ServletException {
		logger.debug("Initializing  Storefront properties");
		
		super.init();
		ServletContext context = super.getServletContext();
		String webRoot = context.getRealPath("/");
		if (webRoot != null) {
			System.setProperty("webapp.root", webRoot);
		}
		
		Enumeration names = super.getInitParameterNames();
		while (names.hasMoreElements()) {
			String name = (String)names.nextElement();
			String value = super.getInitParameter(name);
			if (value != null) {
				System.setProperty(name, StringUtils.resolveProperties(value));
			}
		}
	}

	/* (non-Javadoc)
	 * @see javax.servlet.Servlet#destroy()
	 */
	public void destroy() {
		try {
			logger.debug("Destroying default Struts data source");
			
			BasicDataSource dataSource = ConfigurableDataSource.sInstance;
			if (dataSource != null) {
				dataSource.close();
			}
		}
		catch (SQLException sqle) {
			logger.error("An error occurred whil closing the Struts default data source", sqle);
		}
		super.destroy();
	}

}

⌨️ 快捷键说明

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