我正在编写与此处完全相同的应用程序,我连接到数据库,如果我通过 main 方法将我的 Dao 作为 java 应用程序运行,一切正常;但是如果我在服务器上运行应用程序,那么我会得到:
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NullPointerException
com.tok.dao.ClipDao.getAllClips(ClipDao.java:27)
com.tok.controller.ClipHandler.doGet(ClipHandler.java:34)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:696)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:667)
org.apache.jsp.index_jsp._jspService(index_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
此错误com.tok.dao.ClipDao.getAllClips(ClipDao.java:27)
指向我的 Dao 中的以下行:
语句语句 = connection.createStatement();
这是 ClipDao 构造函数的样子:
private Connection connection = null;
public ClipDao() {
connection = DbUtil.getConnection();
}
更新:
我正在将应用程序的文件导出.war
到tomcat的webapp目录..所以tomcat/libs/
目录下没有postgresql.jar
lib。添加jar后问题解决。