Book.java源代码:
package book;public class Book
{
private String id;
private String name;
private String title; public void setId(String id){
this.id=id;
} public void setName(String name){
this.name=name;
} public void setTitle(String title){
this.title=title;
} public String getId(){
return this.id;
} public String getName(){
return this.name;
} public String getTitle(){
return this.title;
}}BookBean.java源代码:
package book;import java.sql.*;
import java.util.*;public class BookBean{
private DataBaseCon dbcon=new DataBaseCon();
private Connection con=null; public BookBean(){
this.con=dbcon.getCon();
}
public Collection getBooks() throws Exception
{
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from book");
Collection ret=new ArrayList();
while(rs.next())
{
Book temp=new Book();
temp.setId(rs.getString("id"));
temp.setName(rs.getString("name"));
temp.setTitle(rs.getString("title"));
ret.add(temp);
}
return ret;
}}
book.jsp源代码:
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@page contentType="text/html; charset=GBK"%>
<html:html>
<head>
<title>bookstore </title>
</head>
<body>
<center> <h4>请选择想购买的书:</h4>
<table align="center" bgcolor="#008800" border="0" cellpadding="5" cellspacing="2">
<tr bgcolor="#ccccc">
<td align="center" width="70" height="15">书的编号</td>
<td align="center" width="130" height="15">书名</td>
<td align="center" width="45" height="15">作者</td>
</tr> <jsp:useBean id="booksbean" scope="session" class="book.BookBean"/>
<c:set var="books" value="${booksbean.books}"/>
<logic:iterate id="temp1" name="books">
<tr bgcolor="#ccccc">
<td align="center" height="15">
<bean:write name="temp1" property="id"/>
</td>
<td align="center" height="15">
<bean:write name="temp1" property="title"/>
</td>
<td align="center" height="15">
<bean:write name="temp1" property="name"/>
</td>
</tr>
</logic:iterate>
</table>
</center>
</body>
</html:html>
在Builder2006中编译出错:
javax.servlet.ServletException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "value" with value "${booksbean.books}": An error occurred while getting property "books" from an instance of class book.BookBean (java.lang.NullPointerException)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:492)
at org.apache.jsp.book_jsp._jspService(book_jsp.java:177)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
package book;public class Book
{
private String id;
private String name;
private String title; public void setId(String id){
this.id=id;
} public void setName(String name){
this.name=name;
} public void setTitle(String title){
this.title=title;
} public String getId(){
return this.id;
} public String getName(){
return this.name;
} public String getTitle(){
return this.title;
}}BookBean.java源代码:
package book;import java.sql.*;
import java.util.*;public class BookBean{
private DataBaseCon dbcon=new DataBaseCon();
private Connection con=null; public BookBean(){
this.con=dbcon.getCon();
}
public Collection getBooks() throws Exception
{
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from book");
Collection ret=new ArrayList();
while(rs.next())
{
Book temp=new Book();
temp.setId(rs.getString("id"));
temp.setName(rs.getString("name"));
temp.setTitle(rs.getString("title"));
ret.add(temp);
}
return ret;
}}
book.jsp源代码:
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@page contentType="text/html; charset=GBK"%>
<html:html>
<head>
<title>bookstore </title>
</head>
<body>
<center> <h4>请选择想购买的书:</h4>
<table align="center" bgcolor="#008800" border="0" cellpadding="5" cellspacing="2">
<tr bgcolor="#ccccc">
<td align="center" width="70" height="15">书的编号</td>
<td align="center" width="130" height="15">书名</td>
<td align="center" width="45" height="15">作者</td>
</tr> <jsp:useBean id="booksbean" scope="session" class="book.BookBean"/>
<c:set var="books" value="${booksbean.books}"/>
<logic:iterate id="temp1" name="books">
<tr bgcolor="#ccccc">
<td align="center" height="15">
<bean:write name="temp1" property="id"/>
</td>
<td align="center" height="15">
<bean:write name="temp1" property="title"/>
</td>
<td align="center" height="15">
<bean:write name="temp1" property="name"/>
</td>
</tr>
</logic:iterate>
</table>
</center>
</body>
</html:html>
在Builder2006中编译出错:
javax.servlet.ServletException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "value" with value "${booksbean.books}": An error occurred while getting property "books" from an instance of class book.BookBean (java.lang.NullPointerException)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:492)
at org.apache.jsp.book_jsp._jspService(book_jsp.java:177)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
解决方案 »
- struts2获取页面参数存入数据库的问题
- 帮忙分析一下这个jacob读word转换为html 的代码
- jquery tablesorter的问题,如何改变表格记录,重新排序?。。。。。。。。。。。。。。。。。【标题要长】
- select标签传值
- jsp 奇怪的问题
- 如何在不知道执行的SQL语句的情况下,显示出ResultSet中所有记录?
- 哪位大侠有SmartUpload组件
- 菜鸟求助,在线等!
- 关于文本内容转化成网页内容后在text中再显示的乱码问题:)
- 怎么办啊
- 在LOGJ4配置打印日志的时候,不想把JSF里的内容打印出来,该怎么办?
- 如何用javascript实现阶段java中的监听器功能
........
(java.lang.NullPointerException)
...