I am trying to get the properties from system.properties file which looks like this -
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/stud_mng"
duser="root"
dpass=""
logfile=d:/log/test_log.txt
I also mapped this file in my web.xml like this -
<servlet>
<description>
This is the description of my J2EE component
</description>
<display-name>
This is the display name of my J2EE component
</display-name>
<servlet-name>InitServlet</servlet-name>
<servlet-class>com.dts.core.util.InitServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/config/system.properties</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>InitServlet</servlet-name>
<url-pattern>/initservlet</url-pattern>
</servlet-mapping>
Now here this InitServlet.java file problem came, from here I am trying to fetch the properties of system.properties which is saved under config folder. Here is the code which is throwing exception from line props.load(fis);
, I am posting few lines exception and the structure of folder tree -
package com.dts.core.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import com.dts.core.dao.AbstractDataAccessObject;
import com.dts.core.db.DBFactory;
public class InitServlet extends HttpServlet
{
AbstractDataAccessObject dobject;
public void init(ServletConfig sc)
{
ServletContext ctx = sc.getServletContext();
InputStream fis = ctx.getResourceAsStream(sc.getInitParameter("config"));
Properties props = new Properties();
try
{
props.load(fis);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
dobject = new AbstractDataAccessObject();
dobject.setProperties(props);
Mar 27, 2016 1:06:30 AM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet /MobileServices threw load() exception java.lang.NullPointerException at java.util.Properties$LineReader.readLine(Properties.java:434) at java.util.Properties.load0(Properties.java:353) at java.util.Properties.load(Properties.java:341) at com.dts.core.util.InitServlet.init(InitServlet.java:26) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ......
Also I am wondering why configuration file folder is created in Netbeans projects. Can I use this folder to store my system.properties file, if Yes then from here how I will get the properties. See in image the folder I am talking about - Highlight with Pink Color
I will be very thankful for any suggestion/guidance/advice.