我直接运行下面这个函数不出问题,可以找到dbsqlserver.properties.但是发布到Tomcat工程里面去,在JSP页面调用下面函数时就找不到路径,请问如何解决?
public void getValue()
{
Properties pro=new Properties();
try {
InputStream in=new FileInputStream("D:\\Tomcat6.0\\webapps\\MyFirstJSP\\WEB-INF\\classes\\dbConfig\\dbsqlsever.properties");
//File file=new File("dbsqlsever.properties");
//System.out.println(file.getAbsolutePath());
//InputStream in=pro.getClass().getResourceAsStream("/dbConfig/dbsqlsever.properties");
//String root=getRealPath("/dbConfig/dbsqlsever.properties");
pro.load(in);
dirver=pro.getProperty("driver");
url=pro.getProperty("url");
username=new String(pro.getProperty("username").getBytes("ISO-8859-1"),"GBK");
password=new String(pro.getProperty("password").getBytes("ISO-8859-1"),"GBK");
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
下面是错误提示:
D:\Tomcat6.0\bin\dbsqlsever.properties
2009-10-27 8:53:54 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:436)
at java.util.Properties.load0(Properties.java:355)
at java.util.Properties.load(Properties.java:343)
at dbConfig.Rwproperties.getValue(Rwproperties.java:38)
at DAO.DbConnection.<init>(DbConnection.java:18)
at DAO.DBSQLManager.<init>(DBSQLManager.java:24)
at org.apache.jsp.Test_jsp._jspService(Test_jsp.java:91)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
at java.lang.Thread.run(Thread.java:675)
D:\Tomcat6.0\bin\dbsqlsever.properties
2009-10-27 9:12:56 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:436)
at java.util.Properties.load0(Properties.java:355)
at java.util.Properties.load(Properties.java:343)
at dbConfig.Rwproperties.getValue(Rwproperties.java:38)
at DAO.DbConnection.<init>(DbConnection.java:18)
at DAO.DBSQLManager.<init>(DBSQLManager.java:24)
at org.apache.jsp.Test_jsp._jspService(Test_jsp.java:91)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)