在刚开始翻页的时候,没有混乱。在不同条件下查询之后,在点击翻页就会出现,在之前的页码上继续加的现象,而不是显示第二页::
checksysdairy2.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
国家安全和案件情报态势感知平台
查看日志
类型
时间
内容
${programlogls.type}
${programlogls.datetime}
${programlogls.content}
checksystemdairy2.action
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
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;
import tools.PageSystemstatue;
import dao.SystemstatusDao;
import dao.impl.SystemstatusDaoImpl;
import entity.ProgramLog;
import entity.PublicPage;
import entity.conditionMMT;
@WebServlet(name = "checksystemdairyServlet2", urlPatterns = { "/checksystemdairy2.action" })
public class checksystemdairyServlet2 extends HttpServlet {
// 新建业务层对象
SystemstatusDaoImpl sys = new SystemstatusDaoImpl();
// 新建通用分页类对象
PageSystemstatue ps = new PageSystemstatue();
/**
* Constructor of the object.
*/
public checksystemdairyServlet2() {
super();
}
/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
// 存放选中的ip 和 program 保证每一个显示的jsp页面都能拿到 ip和program
String IP = request.getParameter("IP");
String PROGRAM = request.getParameter("PROGRAM");
ProgramLog plog = new ProgramLog();
plog.setIp(IP);
plog.setProgram(PROGRAM);
String mintime = request.getParameter("mintime");
String maxtime = request.getParameter("maxtime");
String stype = request.getParameter("stype");
if (stype.equals("allstyle")) {
String typeall = null;
if (stype.equals("allstyle")) {
typeall = "全部类型";
}
SystemstatusDao ss = new SystemstatusDaoImpl();
ProgramLog programlog = null;
List programlogl = new ArrayList();
List programlogls = new ArrayList();
PublicPage pp = new PublicPage();
conditionMMT mmt = new conditionMMT();
mmt.setMintime(mintime);
mmt.setMaxtime(maxtime);
mmt.setStype(stype);
mmt.setStypename(typeall);
// 接受翻页的指令
String param = request.getParameter("ddpage");
int count;
try {
// 查询符合条件的数据的总条数
count = sys.allgetCount(IP, PROGRAM, mintime, maxtime);
// 计算最后一页的页码
int lastPage = ps.getPagesCount(count, 30);
// 计算应该显示的页码
int pageNo = ps.getFenyePageNo(param, lastPage);
pp.setLastPage(lastPage);
pp.setPageNo(pageNo);
programlogl = ss.allgetSystemCondition(IP, PROGRAM, mintime,
maxtime, pageNo, 30);
for (int i = 0; i < programlogl.size(); i++) {
String type = null;
String type1 = null;
String datetime = null;
String content = null;
String datetime1 = null;
String ip = null;
String program = null;
programlog = new ProgramLog();
type1 = programlogl.get(i).getType();
if (type1.equals("standard")) {
type = "标准";
}
if (type1.equals("warning")) {
type = "警告";
}
if (type1.equals("error")) {
type = "错误";
}
if (type1.equals("unknown")) {
type = "未知";
}
datetime1 = programlogl.get(i).getDatetime();
datetime = datetime1.substring(0, 19);
content = programlogl.get(i).getContent();
ip = programlogl.get(i).getIp();
program = programlogl.get(i).getProgram();
// 存入programlog对象!
programlog.setType(type);
programlog.setDatetime(datetime);
programlog.setContent(content);
programlog.setIp(ip);
programlog.setProgram(program);
// 将对象存入programlogls集合!
programlogls.add(programlog);
}
} catch (Exception e) {
e.printStackTrace();
}
// 看看每次传到 2.jsp页面的是什么?? 为什么在之前的基础上,加页数!
System.out.println("…………………………………………………………………………………………………………………………………………………………");
System.out.println("最后页数:::All "+pp.getLastPage());
System.out.println("当前页数::All "+pp.getPageNo());
System.out.println("小日期:::All "+mmt.getMintime());
System.out.println("大日期:::All "+mmt.getMaxtime());
System.out.println("类型::All "+mmt.getStype());
System.out.println("ip:::All "+plog.getIp());
System.out.println("program::All "+plog.getProgram());
request.getSession().setAttribute("pp", pp);
request.getSession().setAttribute("mmt", mmt);
request.getSession().setAttribute("programlogls", programlogls);
request.getSession().setAttribute("programlog", programlog);
request.getSession().setAttribute("plog", plog);
request.getRequestDispatcher("checksysdairy2.jsp").forward(request,response);
out.flush();
out.close();
} else {
SystemstatusDao ss = new SystemstatusDaoImpl();
ProgramLog programlog = null;
List programlogl = new ArrayList();
List programlogls = new ArrayList();
PublicPage pp = new PublicPage();
conditionMMT mmt = new conditionMMT();
mmt.setMintime(mintime);
mmt.setMaxtime(maxtime);
mmt.setStype(stype);
// 接受翻页的指令
String param = request.getParameter("ddpage");
int count;
try {
// 查询符合条件的数据的总条数
count = sys.getCount2(IP, PROGRAM, mintime, maxtime, stype);
if (count == 0) {
String style = null;
if (stype.equals("standard")) {;
}
if (stype.equals("warning")) {;
}
if (stype.equals("error")) {;
}
if (stype.equals("unknown")) {;
}
mmt.setStypename(style);
//计算最后一页的页码
int lastPage=ps.getPagesCount(count,30);
//计算应该显示的页码
int pageNo1=ps.getFenyePageNoo(param,lastPage);
int pageNo=pageNo1+1;
pp.setLastPage(lastPage);
pp.setPageNo(pageNo1);
programlogl = ss.getSystemCondition(IP, PROGRAM, mintime,
maxtime, stype, pageNo, 30);
} else {
// 计算最后一页的页码
int lastPage = ps.getPagesCount(count, 30);
// 计算应该显示的页码
int pageNo = ps.getFenyePageNo(param, lastPage);
pp.setLastPage(lastPage);
pp.setPageNo(pageNo);
programlogl = ss.getSystemCondition(IP, PROGRAM, mintime,
maxtime, stype, pageNo, 30);
for (int i = 0; i < programlogl.size(); i++) {
String type = null;
String type1 = null;
String datetime = null;
String content = null;
String datetime1 = null;
String ip = null;
String program = null;
programlog = new ProgramLog();
type1 = programlogl.get(i).getType();
if (type1.equals("standard")) {
type = "标准";
}
if (type1.equals("warning")) {
type = "警告";
}
if (type1.equals("error")) {
type = "错误";
}
if (type1.equals("unknown")) {
type = "未知";
}
mmt.setStypename(type);
datetime1 = programlogl.get(i).getDatetime();
datetime = datetime1.substring(0, 19);
content = programlogl.get(i).getContent();
ip = programlogl.get(i).getIp();
program = programlogl.get(i).getProgram();
// 存入programlog对象!
programlog.setType(type);
programlog.setDatetime(datetime);
programlog.setContent(content);
programlog.setIp(ip);
programlog.setProgram(program);
// 将对象存入programlogls集合!
programlogls.add(programlog);
}
}
} catch (Exception e) {
e.printStackTrace();
}
request.getSession().setAttribute("pp", pp);
request.getSession().setAttribute("mmt", mmt);
request.getSession().setAttribute("programlogls", programlogls);
request.getSession().setAttribute("programlog", programlog);
request.getSession().setAttribute("plog", plog);
request.getRequestDispatcher("checksysdairy2.jsp").forward(request,response);
out.flush();
out.close();
}
}
/**
* The doPost method of the servlet.
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
/**
* Initialization of the servlet.
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
PageSystem2.action
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
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;
import tools.PageSystemstatue;
import dao.SystemstatusDao;
import dao.impl.SystemstatusDaoImpl;
import entity.ProgramLog;
import entity.PublicPage;
import entity.conditionMMT;
@WebServlet(name = "PageSystemServlet2", urlPatterns = { "/PageSystem2.action" })
public class PageSystemServlet2 extends HttpServlet {
//新建业务层对象
SystemstatusDaoImpl sys=new SystemstatusDaoImpl();
//新建通用分页类对象
PageSystemstatue ps=new PageSystemstatue();
/**
* Constructor of the object.
*/
public PageSystemServlet2() {
super();
}
/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String sip = request.getParameter("sip");
String sprogram = request.getParameter("sprogram");
String mintime=request.getParameter("mintime");
String maxtime=request.getParameter("maxtime");
String stype=request.getParameter("stype");
if(stype.equals("allstyle")){
String typeall = null;
if (stype.equals("allstyle")) {
typeall = "全部类型";
}
SystemstatusDao ss=new SystemstatusDaoImpl();
ProgramLog programlog= null;
List programlogl=new ArrayList();
List programlogls=new ArrayList();
PublicPage pp = new PublicPage();
conditionMMT mmt = new conditionMMT();
mmt.setMintime(mintime);
mmt.setMaxtime(maxtime);
mmt.setStype(stype);
mmt.setStypename(typeall);
//接受翻页的指令
String param=request.getParameter("ddpage");
int count;
try {
//查询符合条件的数据的总条数
count = sys.allgetCount(sip,sprogram,mintime,maxtime);
//计算最后一页的页码
int lastPage=ps.getPagesCount(count,30);
//计算应该显示的页码
int pageNo=ps.getFenyePageNo(param,lastPage);
pp.setLastPage(lastPage);
pp.setPageNo(pageNo);
programlogl=ss.allgetSystemCondition(sip,sprogram,mintime,maxtime,pageNo,30);
for(int i=0;i programlogl=new ArrayList();
List programlogls=new ArrayList();
PublicPage pp = new PublicPage();
//接受翻页的指令0
String param=request.getParameter("ddpage");
int count;
try {
//查询符合条件的数据的总条数
count = sys.getCount2(sip,sprogram,mintime,maxtime,stype);
if(count==0){
//计算最后一页的页码
int lastPage=ps.getPagesCount(count,30);
//计算应该显示的页码
int pageNo1=ps.getFenyePageNoo(param,lastPage);
int pageNo=pageNo1+1;
pp.setLastPage(lastPage);
pp.setPageNo(pageNo1);
programlogl=ss.getSystemCondition(sip,sprogram,mintime,maxtime,stype,pageNo,30);
}else{
//计算最后一页的页码
int lastPage=ps.getPagesCount(count,30);
//计算应该显示的页码
int pageNo=ps.getFenyePageNo(param,lastPage);
pp.setLastPage(lastPage);
pp.setPageNo(pageNo);
programlogl=ss.getSystemCondition(sip,sprogram,mintime,maxtime,stype,pageNo,30);
}
for(int i=0;i
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
/**
* Initialization of the servlet.
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
翻页的方法::
package tools;
public class PageSystemstatue {
private int totalPages;
public int getPagesCount(int count,int size) {
// TODO Auto-generated method stub
int totalCount=count;
totalPages = totalCount % size == 0 ? totalCount / size : totalCount
/ size + 1;
return totalPages;
}
private int currentPageNo;
public int getFenyePageNo(String param,int lastPage) {
if ("first".equals(param) || null == param) {
currentPageNo = 1;
} else if ("next".equals(param)) {
if (currentPageNo < lastPage) {
currentPageNo++;
}
} else if ("previous".equals(param)) {
if (currentPageNo > 1) {
currentPageNo--;
}
} else if ("last".equals(param)) {
currentPageNo = lastPage;
}
return currentPageNo;
}
private int currentPageNoo;
public int getFenyePageNoo(String param, int lastPage) {
if ("first".equals(param) || null == param) {
currentPageNoo = 0;
} else if ("next".equals(param)) {
if (currentPageNoo < lastPage) {
currentPageNoo = 0;
}
} else if ("previous".equals(param)) {
if (currentPageNoo > 1) {
currentPageNoo = 0;
}
} else if ("last".equals(param)) {
currentPageNoo = 0;
}
return currentPageNoo;
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
太长,而且你格式都还没排好。。。。。。。。。
太长看的眼花,把关键逻辑代码贴出来就好了
太长...这平台也不是这么用的吧。
自己的代码只有自己懂~慢慢debug吧