In debug a javabean, how check it is giving to other component CORRECT data-DAO/pools
textbook example 12-3(david pasons java/xml) - DAO / DB-POOL / TOMCAT
At localhost
http://localhost:8080/jspadv/webhome...listclaims.jsp
I do NOT know, how debug? In debug a javabean, how check it is giving to other component CORRECT data?
The below means not find data ...? in db?
Code:
org.apache.jasper.JasperException: javax.el.ELException: Error reading 'claims' on type com.webhomecover.beans.ClaimCollection
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
javax.el.ELException: Error reading 'claims' on type com.webhomecover.beans.ClaimCollection
javax.el.BeanELResolver.getValue(BeanELResolver.java:66)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
org.apache.el.parser.AstValue.getValue(AstValue.java:118)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)
org.apache.jsp.listclaims_jsp._jspx_meth_c_005fforEach_005f0(listclaims_jsp.java:125)
org.apache.jsp.listclaims_jsp._jspService(listclaims_jsp.java:99)
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)
root cause
java.lang.NullPointerException
com.webhomecover.dao.ClaimDAO.readClaims(Unknown Source)
com.webhomecover.model.ModelFacade.getClaims(Unknown Source)
com.webhomecover.beans.ClaimCollection.getClaims(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
org.apache.el.parser.AstValue.getValue(AstValue.java:118)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)
org.apache.jsp.listclaims_jsp._jspx_meth_c_005fforEach_005f0(listclaims_jsp.java:125)
org.apache.jsp.listclaims_jsp._jspService(listclaims_jsp.java:99)
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)
Code:
<?xml version="1.0"?>
<!-- File: listclaims.jsp -->
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
version="2.0">
<jsp:directive.page isELIgnored="false" />
<jsp:directive.page contentType="text/html"/>
<jsp:output omit-xml-declaration="false"
doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link href="webhomecover.css" rel="stylesheet" type="text/css" />
<title>Insurance Claims</title>
</head>
<body>
<p>Here is a list of claims</p>
<table>
<tr>
<th>reference</th><th>description</th><th>amount</th><th>approved</th><th>claimDate</th>
</tr>
<jsp:useBean id="claimCollection" class="com.webhomecover.beans.ClaimCollection" />
<c:forEach var="claim" items="${claimCollection.claims}">
<tr>
<td><c:out value="${claim.reference}" /></td>
<td><c:out value="${claim.description}" /></td>
<td><c:out value="${claim.amount}" /></td>
<td><c:out value="${claim.approved}" /></td>
<td><c:out value="${claim.claimDate}" /></td>
</tr>
</c:forEach>
</table>
</body>
</html>
</jsp:root>
is it faults where clause?
claims is a list of claim.
String x=new String(); provides empty string or needed inside parenthesis "" (doublequotes)?
is it faults where clause?
Code:
//com.webhomecover.beans.ClaimCollection
package com.webhomecover.beans;
import java.util.*;
import com.webhomecover.model.ModelFacade;
import com.webhomecover.model.Claim;
public class ClaimCollection
{
private String whereClause = new String();
public String getWhereClause()
{
return whereClause;
}
public void setWhereClause(String whereClause)
{
this.whereClause = whereClause;
}
public Collection<Claim> getClaims()
{
Collection<Claim> claims = ModelFacade.getClaims(whereClause);
return claims;
}
}
Code:
package com.webhomecover.model;
import com.webhomecover.dao.ClaimDAO;
import java.util.Collection;
public class ModelFacade
{
public static Collection<Claim> getClaims(String whereClause)
{
// if no 'where' clause string is passed in, create an empty string
if(whereClause == null)
{
whereClause = new String();
}
ClaimDAO cdao = new ClaimDAO();
Collection<Claim> claimCollection = cdao.readClaims(whereClause);
return claimCollection;
}
}
Code:
// com.webhomecover.dao.ClaimDAO.java
.....................
public Collection<Claim> readClaims(String whereClause)
{
Collection<Claim> claims = new ArrayList<Claim>();
try
{
getConnection();
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery("SELECT * FROM claim " + whereClause);
String reference = null;
String description = null;
double amount = 0.0;
boolean approved = false;
java.sql.Date claimDate = null;
Claim claim = null;
while(results.next())
{
reference = results.getString("reference");
description = results.getString("description");
amount = results.getDouble("amount");
approved = results.getBoolean("approved");
claimDate = results.getDate("claimDate");
claim = new Claim();
claim.setReference(reference);
claim.setDescription(description);
claim.setAmount(amount);
claim.setApproved(approved);
claim.setClaimDate(claimDate);
claims.add(claim);
}
results.close();
results = null;
statement.close();
statement = null;
connection.close();
connection = null;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
cleanUp();
}
return claims;
} .....................