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.mail.Mail; 35 36 54 public class MailServlet extends HttpServlet { 55 56 58 60 62 64 public void init() { 65 try { 66 String path = getInitParameter( "mailproperties" ); 67 68 if ( path == null ) { 69 path = getServletContext().getRealPath( "WEB-INF/mail.properties" ); 70 } 71 72 if ( !path.startsWith( "/" ) ) { 73 path = getServletContext().getRealPath( path ); 74 75 if ( path == null ) { 76 getServletContext().log( 77 "MailServlet: Couldn't get real path for " + path + 78 "; defaulting to WEB-INF/mail.properties." ); 79 80 path = getServletContext().getRealPath( "WEB-INF/mail.properties" ); 81 } 82 } 83 84 InputStream in = 85 new FileInputStream ( path ); 86 87 Properties props = new Properties (); 88 props.load( in ); 89 90 in.close(); 91 92 Mail.init( props ); 93 } 94 catch ( Exception e ) { 95 getServletContext().log( 96 "MailServlet: Unexpected exception while initializing " + 97 "MailServlet with init param mailproperties = " + 98 getInitParameter( "mailproperties" ) + ": " + e ); 99 } 100 } 101 102 public void doGet( 103 HttpServletRequest req, 104 HttpServletResponse res) { 105 } 106 107 109 } 111 | Popular Tags |