我正在编写与here完全相同的应用程序,我连接到数据库,如果我通过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中的下面一行:
Statement statement = connection.createStatement();
这就是ClipDao构造函数的样子:
private Connection connection = null;
public ClipDao() {
connection = DbUtil.getConnection();
}
我正在将应用程序的.war
文件导出到tomcat的webapp目录..所以在tomcat/libs/
目录下没有postgresql.jar
lib。添加jar问题后解决。
答案 0 :(得分:1)