1 20 21 package com.methodhead.servlet; 22 23 import java.io.FileInputStream ; 24 import java.io.InputStream ; 25 26 import java.util.Properties ; 27 28 import javax.servlet.ServletContext ; 29 30 import javax.servlet.http.HttpServlet ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 34 import com.methodhead.persistable.ConnectionSingleton; 35 36 55 public class ConnectionServlet extends HttpServlet { 56 57 59 61 63 65 public void init() { 66 try { 67 String dbProperties = getInitParameter( "dbproperties" ); 68 69 if ( dbProperties == null ) { 70 getServletContext().log( 71 "ConnectionServlet: dbproperties init-param has not been set; " + 72 "defaulting to WEB-INF/db.properties" ); 73 dbProperties = 74 getServletContext().getRealPath( "WEB-INF/db.properties" ); 75 } 76 77 String file = dbProperties; 78 if ( !dbProperties.startsWith( "/" ) ) { 79 file = getServletContext().getRealPath( dbProperties ); 80 81 if ( file == null ) { 82 getServletContext().log( 83 "ConnectionServlet: Couldn't get real path for " + dbProperties + 84 "; defaulting to WEB-INF/db.properties." ); 85 file = getServletContext().getRealPath( "WEB-INF/db.properties" ); 86 } 87 } 88 89 InputStream in = 90 new FileInputStream ( file ); 91 92 Properties dbProps = new Properties (); 93 dbProps.load( in ); 94 95 in.close(); 96 97 ConnectionSingleton.init( dbProps ); 98 } 99 catch ( Exception e ) { 100 getServletContext().log( 101 "ConnectionServlet: Unexpected exception while initializing " + 102 "ConnectionServlet with init param dbproperties = " + 103 getInitParameter( "dbproperties" ) + ": " + e ); 104 } 105 } 106 107 public void doGet( 108 HttpServletRequest req, 109 HttpServletResponse res) { 110 } 111 112 114 } 116 | Popular Tags |