I
Ike
I have a servlet which uses public void service() wherein I attempt to load
a properties file, located in the same directory as my servlet.class file
being executed (WEB-INF/classes).
public void init(ServletConfig config) throws ServletException {
// This method initializes the servlet and only gets call once.
// Allocate all of the servlet resources here.
super.init(config);
Properties props = new Properties();
ClassLoader loader = this.getClass().getClassLoader();
InputStream istream = loader.getResourceAsStream("xx.properties");
try{
props.load(istream);//<-----------------this is line 38
driver = props.getProperty("driver");
}catch(.....){...}
}
My xx.properties files merely looks like:
driver = org.gjt.mm.mysql.Driver
url = jdbc:mysql://localhost:3306/dbname?autoReconnect=true
My servlet bombs at line 38 (marked above) with the following stack trace,
below. For the life of me, I cannot figure out why -- if anyone has a clue,
please enlighten me. This used to work perfectly under a different server.
Thanks, Ike:
Feb 27, 2006 10:07:52 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:365)
at java.util.Properties.load(Properties.java:293)
at TestServlet3.init(TestServlet3.java:38)
at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:10
91)
at
org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:750)
at
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java
:369)
at
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:178)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126
)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105
)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:307)
at
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:748)
at
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:678)
at
org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:871)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:684)
at java.lang.Thread.run(Thread.java:595)
a properties file, located in the same directory as my servlet.class file
being executed (WEB-INF/classes).
public void init(ServletConfig config) throws ServletException {
// This method initializes the servlet and only gets call once.
// Allocate all of the servlet resources here.
super.init(config);
Properties props = new Properties();
ClassLoader loader = this.getClass().getClassLoader();
InputStream istream = loader.getResourceAsStream("xx.properties");
try{
props.load(istream);//<-----------------this is line 38
driver = props.getProperty("driver");
}catch(.....){...}
}
My xx.properties files merely looks like:
driver = org.gjt.mm.mysql.Driver
url = jdbc:mysql://localhost:3306/dbname?autoReconnect=true
My servlet bombs at line 38 (marked above) with the following stack trace,
below. For the life of me, I cannot figure out why -- if anyone has a clue,
please enlighten me. This used to work perfectly under a different server.
Thanks, Ike:
Feb 27, 2006 10:07:52 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:365)
at java.util.Properties.load(Properties.java:293)
at TestServlet3.init(TestServlet3.java:38)
at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:10
91)
at
org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:750)
at
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java
:369)
at
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:178)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126
)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105
)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:307)
at
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:748)
at
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:678)
at
org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:871)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:684)
at java.lang.Thread.run(Thread.java:595)