myeclipse. jsp. sqlsever

1.运行这个,报出这样的错误。

2.
package com.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.beans.Book;
import com.tools.DBConnection;
public class PageQueryDao {

//分页查询所有书目信息 
public List<Book> getPageList(int page){    

    List<Book> list = new ArrayList<Book>(); 
    DBConnection DB = new DBConnection();   
    Connection conn=DB.getCon(); 

    int m = (page-1)*Book.PAGE_SIZE;
    if( m > 0 || m == 0){
    String sql = "select top 6 *  from books where BookID > "+ m ;
    //String sql="select * from books order by BookID asc limit ?,?";//limit关键字   
    try {                   
        PreparedStatement pstm=conn.prepareStatement(sql);          
        //pstm.setInt(1, (page-1)*Book.PAGE_SIZE); //设置查询记录的开始位置      
        //pstm.setInt(2, Book.PAGE_SIZE); //设置查询数据所返回的记录数         
        ResultSet rs = pstm.executeQuery();         
        while(rs.next()){           
            Book book=new Book();       
            book.setBookId(rs.getInt("BookID"));        
            book.setName(rs.getString("Name"));     
            book.setAuthor(rs.getString("Author"));     
            book.setPublisher(rs.getString("Publisher"));       
            book.setPrice(rs.getString("Price"));           
            list.add(book);             
            }   

        rs.close();     
        pstm.close();       
        conn.close();
        } catch (SQLException e) {  
            // TODO Auto-generated catch block      
            e.printStackTrace();        
            }       
    }
    return list;
}

//查询总记录数 
public int FindCounts(){    
    int count=0; 
    DBConnection DB=new DBConnection();     
    Connection conn=DB.getCon();    
    String sql="select count(*) from books";    
    try {                       
        PreparedStatement pstm=conn.prepareStatement(sql);      
        ResultSet rs=pstm.executeQuery();           
        if(rs.next()){//rs里就一个值               
            count=rs.getInt(1);                         
            }           
        rs.close();         
        conn.close();       
        } catch (SQLException e){       
            // TODO Auto-generated catch block      
            e.printStackTrace();        
            } 
    return count;   
    }


/*public static void main(String[] args){
    System.out.println((getPageList(0)).size() );
    System.out.println((getPageList(1)).size() );
    List<Book> list = getPageList(0);
    if(list != null){
    for(Book b:list){
        System.out.println(b.getBookId());
        System.out.println(b.getName());
        System.out.println(b.getPrice());
        System.out.println(b.getPublisher());
        System.out.println(b.getAuthor());          
    }       
}
}*/

3.<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@page import="java.util.List"%><%@page import="com.beans.Book"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

图书信息列表 <!-- --> a:link{color:#FF4500;text-decoration:none}/*未访问,红色,无下划线*/ a:active{color:blue;}/*激活,红色*/ a:visited{color:red;text-decoration:none}/*已访问,紫色,无下划线*/ a:hover{color:yellow;text-decoration:underline}/*鼠标移动上面,蓝色,下划线*/

<%! int i=1,j=1; %> <% List list = request.getAttribute("list");%> <% for(j=1;j<=2;j++){ %> <% if(list != null){ for(Book b:list){ if(j==2){ if(b.getBookId()<=3||(b.getBookId()>=7&&b.getBookId()<=9)) continue; } %>

喵喵网上书店

ISDN :<%=b.getBookId() %>
书 名:<%=b.getName() %>
作 者:<%=b.getAuthor() %>
出 版:<%=b.getPublisher() %>
价 格:<%=b.getPrice() %>
   <%= request.getAttribute("bar") %>

4.package com.servlets;import java.io.IOException;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.Dao.PageQueryDao;import com.beans.Book;public class PageQueryServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { int currpage=1; // if(request.getParameter("page") != null){ // currpage = Integer.parseInt(request.getParameter("page")); // } PageQueryDao pagedao = new PageQueryDao(); List list = pagedao.getPageList(currpage);//查询当前页记录 request.setAttribute("list", list); int pages; //计算查询总页数 int count = pagedao.FindCounts(); if(count%Book.PAGE_SIZE == 0){ pages = count/Book.PAGE_SIZE; } else{ pages = count/Book.PAGE_SIZE+1; } System.out.println(pages); StringBuffer sb=new StringBuffer(); //构建分页条 for(int i = 1;i <= pages;i++){ if(i == currpage){ sb.append("『" + i + "』"); } else{ sb.append(" 下一页 "); } sb.append(" "); } request.setAttribute("bar", sb.toString()); request.getRequestDispatcher("books.jsp").forward(request, response); //请求转发 } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); }}

就是这几个文件,数据库能成功连接。PageDao中的主函数能成功运行。就是jsp中无法获取list中的信息。PageServlet无法运行显示出books.jsp界面的相关信息。

希望大神们赐教。图片

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问