我在 Spring JSP 中运行自定义标记。我收到以下错误消息。
java.lang.NullPointerException
com.dao.Poll1DAO.getVotes(Poll1DAO.java:27)
com.tags.Poll1Tag.doTag(Poll1Tag.java:23)
org.apache.jsp.WEB_002dINF.pages.PollPage_jsp._jspx_meth_myTag1_005fpoll1_005f0(PollPage_jsp.java:602)
org.apache.jsp.WEB_002dINF.pages.PollPage_jsp._jspService(PollPage_jsp.java:195)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1265)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1016)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:965)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:859)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:883)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:781)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
这是 Poll1DAO.getVotes()。
public HashMap<String, Object> getVotes() {
// following line is line 27, referenced in error message
return (HashMap<String, Object>) this.getJdbcTemplate().queryForMap(
"select yes, no from poll1 where id = 1");
}
这是 Poll1Tag.doTag()。
Poll1DAO poll1DAO = new Poll1DAO();
public void doTag() throws JspException, IOException {
PageContext pageContext = (PageContext) getJspContext();
boolean foundCookie = cookieFound();
pageContext.setAttribute("foundCookiePoll1", foundCookie);
if (foundCookie) {
// following line is line 23, referenced in error message
HashMap<String, Object> poll1Votes = poll1DAO.getVotes();
pageContext.setAttribute("poll1Yes", (int) poll1Votes.get("yes"));
pageContext.setAttribute("poll1No", (int) poll1Votes.get("no"));
}
}