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)