我做在线书店!!
首业程序代码是:
<%request.setCharacterEncoding("gb2312");
if(session.getAttribute("booklist")==null){
    response.sendRedirect("/bookshoponline/showbook");}%>
显示主业信息代码是:
<%
Vector booklist=(Vector)session.getAttribute("booklist");
while(booklist.size()>=0){
int i=0;
BookInformation book=(BookInformation)booklist.elementAt(i);%> 
<tr>
<td align=center><%=book.getName()%></td>
<td align=center><%=book.getAuthor()%></td>
<td align=center><%=book.getPublisher()%></td>
<td align=center><%=book.getType()%></td>
<td align=center><%=book.getPrice()%></td>
<%if(session.getAttribute("userid")!=null){%>    
</tr>
<%i++;}%>    
booklist是提交给一个Serlvet响应来的:
代码是:
if(session.getAttribute("booklist")!=null){
   session.removeAttribute("booklist");
       }
Vector booklist=new Vector();
//中间为联系数据库以及判断首业提交信息代码,最后把数据放到了booklist里.
其中BookInformation就是普通的JAVABEAN
while(rs.next()){
           BookInformation bookinf=new BookInformation(rs.getString("id"),
             rs.getString("name"),
             rs.getString("author"),
             rs.getString("publisher"),
             rs.getString("price"),
             rs.getString("type"));
           booklist.addElement(bookinf);
       }
session.setAttribute("booklist", booklist);
         response.sendRedirect("/bookshoponline/index.jsp");
但是响应的数据却报错!!

解决方案 »

  1.   

    异常是:为什么说我是空指针异常呢??(我的数据库里是有数据的)
    org.apache.jasper.JasperException: Exception in JSP: /index.jsp:213210:     <th align=center bgcolor="#FFFFFF" ><span class="STYLE8"><strong>单价</strong></span></th>
    211:     <th align=center bgcolor="#FFFFFF" ><span class="STYLE8"><strong>购物车</strong></span></th>
    212:    <%Vector booklist=(Vector)session.getAttribute("booklist");
    213:     while(booklist.size()>=0){
    214:         int i=0;
    215:       BookInformation book=(BookInformation)booklist.elementAt(i);
    216: 
    Stacktrace:
        org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause java.lang.NullPointerException
        org.apache.jsp.index_jsp._jspService(index_jsp.java:267)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
      

  2.   

    错误就是在index.jsp中出现了空指针,你看看你哪个变量引用发生了空指针错误了。我倒是看到另外一个错误:
    while(booklist.size()>=0){
    int i=0;
    BookInformation book=(BookInformation)booklist.elementAt(i);%>
    <tr>
    <td align=center><%=book.getName()%></td>
    <td align=center><%=book.getAuthor()%></td>
    <td align=center><%=book.getPublisher()%></td>
    <td align=center><%=book.getType()%></td>
    <td align=center><%=book.getPrice()%></td>
    <%if(session.getAttribute("userid")!=null){%>
    </tr>
    <%i++;}%> 
    你这样定义首先你的while循环没有结束条件,另外你的是中取的都是Vector中的第一个元素。