code091.java
package pack02;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//FindServlet�ִ࣬�з�ҳ�Ĺ���,��code093.jsp�������
@WebServlet(name="code091",urlPatterns = "/page04/pack02.code091")
public class code091 extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
int currPage = 1; //��ǰҳ
if (request.getParameter("page") != null)
{
currPage = Integer.parseInt(request.getParameter("page"));
}
code090 dao = new code090(); //BookDao
List<code089> list1 = dao.find(currPage); // Book
request.setAttribute("list", list1);
int pages;
int count = dao.findCount();
if (count % code089.PAGE_SIZE == 0)
{
pages = count / code089.PAGE_SIZE;
}
else
{
pages = count / code089.PAGE_SIZE + 1;
}
StringBuffer buffer = new StringBuffer();
for (int i = 1; i <= pages; i++)
{
if (i == currPage)
{
buffer.append("[" + i + "]");
}
else
{
buffer.append("<a href='pack02.code091?page=" + i + "'>" + i + "</a>");
}
buffer.append(" ");
}
request.setAttribute("bar", buffer.toString());
request.getRequestDispatcher("code092.jsp").forward(request, response); //������ʾ
}
}