InitPrint.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:2k
源码类别:
OA系统
开发平台:
Java
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.io.*;
- import java.util.*;
- import explato.database.*;
- public class InitPrint extends HttpServlet {
- public void service( HttpServletRequest req, HttpServletResponse res ) {
- PrintWriter out = null;
- try {
- res.setContentType( "text/html" );
- out = res.getWriter();
- //......
- ConnectionManager cm = new ConnectionManager();
- //File f1=new File("db.properties");
- ServletContext application = getServletContext();
- String sPath=application.getRealPath("db.properties");
- String sPath1=application.getRealPath("db.log");
- cm.setDBProp( sPath ); //设置数据库连接配置文件
- cm.setLogFile( sPath1 ); //设置日志文件
- cm.setTrace( true ); //是否需要记录日志
- application.setAttribute( "fcConPoolManager", cm ); //application是javax.servlet.ServletContext对象,也就是JSP中的application对象,此对象在整个WEB应用中是唯一的
- //......
- //启动Session
- //HttpSession session = req.getSession(true);
- //session.setAttribute("graphdata", "");
- //
- out.println( "<html><body>" );
- out.println( "" );
- out.println( "init eReport Ok!</body></html>" );
- }
- catch( Exception e ) {
- out.println( "init not success!</body></html>" );
- e.printStackTrace( out );
- }
- }
- //destroy()方法会在服务器正常关闭时执行
- public void destroy() {
- try {
- ServletContext application = getServletContext();
- ConnectionManager cm = (ConnectionManager)application.getAttribute( "fcConPoolManager" );
- cm.release(); //关闭所有连接,撤销驱动程序注册
- }catch( Exception e ) {}
- super.destroy();
- }
- }