⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list_0002ejsp_jsp.java

📁 在jsp中实现分页显示
💻 JAVA
字号:
import java.sql.*;
import com.bict.Common;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;


public class list_0002ejsp_jsp extends HttpJspBase {


    static {
    }
    public list_0002ejsp_jsp( ) {
    }

    private static boolean _jspx_inited = false;

    public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
    }

    public void _jspService(HttpServletRequest request, HttpServletResponse  response)
        throws java.io.IOException, ServletException {

        JspFactory _jspxFactory = null;
        PageContext pageContext = null;
        HttpSession session = null;
        ServletContext application = null;
        ServletConfig config = null;
        JspWriter out = null;
        Object page = this;
        String  _value = null;
        try {

            if (_jspx_inited == false) {
                synchronized (this) {
                    if (_jspx_inited == false) {
                        _jspx_init();
                        _jspx_inited = true;
                    }
                }
            }
            _jspxFactory = JspFactory.getDefaultFactory();
            response.setContentType("text/html; charset=GBK");
            pageContext = _jspxFactory.getPageContext(this, request, response,
            			"", true, 8192, true);

            application = pageContext.getServletContext();
            config = pageContext.getServletConfig();
            session = pageContext.getSession();
            out = pageContext.getOut();

            // HTML // begin [file="/list.jsp";from=(0,48);to=(1,0)]
                out.write("\r\n");

            // end
            // HTML // begin [file="/list.jsp";from=(1,47);to=(13,0)]
                out.write("\r\n<html>\r\n<head>\r\n<title>\r\nlist\r\n</title>\r\n</head>\r\n<center>\r\n<body bgcolor=\"#ffffff\">\r\n<h1>\r\n学生信息显示!!!\r\n</h1>\r\n");

            // end
            // begin [file="/list.jsp";from=(13,2);to=(37,0)]
                
                int intPageSize; //一页显示的记录数
                int intRowCount; //记录总数
                int intPageCount; //总页数
                int intPage; //待显示页码
                String strPage;
                String sql="select * from student";
                intPageSize = 2; //设置一页显示的记录数
                intRowCount=Common.getResultCount(sql);//记录总数
                intPageCount=(intRowCount+intPageSize-1)/intPageSize;//总页数
                ResultSet rs=Common.executeQuery(sql);
                
                //取得待显示页码
                strPage = request.getParameter("page");
                if(strPage==null){//表明没有page参数,显示第一页数据
                    intPage = 1;
                }else{
                    intPage = Integer.parseInt(strPage);//将字符串转换成整型
                    if(intPage<1){
                        intPage = 1;
                    }else if(intPage>intPageCount){
                        intPage=intPageCount;
                    }
                }
            // end
            // HTML // begin [file="/list.jsp";from=(37,2);to=(44,0)]
                out.write("\r\n<form method=\"post\" action=\"list.jsp\">\r\n\r\n<table border>\r\n<tr>\r\n    <th>编号</th><th>用户名</th><th>年龄</th><th>来源地</th>\r\n</tr>\r\n");

            // end
            // begin [file="/list.jsp";from=(44,2);to=(50,0)]
                
                 if(intPageCount>0){
                    rs.absolute((intPage-1) * intPageSize + 1);
                    //显示数据
                    int i = 0;
                    while(i<intPageSize && !rs.isAfterLast()){
            // end
            // HTML // begin [file="/list.jsp";from=(50,2);to=(52,6)]
                out.write("\r\n<tr>\r\n  <td>");

            // end
            // begin [file="/list.jsp";from=(52,9);to=(52,24)]
                out.print(rs.getInt("id"));
            // end
            // HTML // begin [file="/list.jsp";from=(52,26);to=(53,6)]
                out.write("</td>\r\n  <td>");

            // end
            // begin [file="/list.jsp";from=(53,9);to=(53,29)]
                out.print(rs.getString("name"));
            // end
            // HTML // begin [file="/list.jsp";from=(53,31);to=(54,6)]
                out.write("</td>\r\n  <td>");

            // end
            // begin [file="/list.jsp";from=(54,9);to=(54,25)]
                out.print(rs.getInt("age"));
            // end
            // HTML // begin [file="/list.jsp";from=(54,27);to=(55,6)]
                out.write("</td>\r\n  <td>");

            // end
            // begin [file="/list.jsp";from=(55,9);to=(55,32)]
                out.print(rs.getString("address"));
            // end
            // HTML // begin [file="/list.jsp";from=(55,34);to=(56,29)]
                out.write("</td>\r\n  <td><a href=\"delete.jsp?id=");

            // end
            // begin [file="/list.jsp";from=(56,32);to=(56,47)]
                out.print(rs.getInt("id"));
            // end
            // HTML // begin [file="/list.jsp";from=(56,49);to=(58,0)]
                out.write("\">删除 </a></td>\r\n</tr>\r\n");

            // end
            // begin [file="/list.jsp";from=(58,2);to=(63,0)]
                
                  rs.next();
                  i++;
                   }
                 }
            // end
            // HTML // begin [file="/list.jsp";from=(63,2);to=(66,1)]
                out.write("\r\n</table>\r\n\r\n第");

            // end
            // begin [file="/list.jsp";from=(66,4);to=(66,11)]
                out.print(intPage);
            // end
            // HTML // begin [file="/list.jsp";from=(66,13);to=(66,16)]
                out.write("页 共");

            // end
            // begin [file="/list.jsp";from=(66,19);to=(66,31)]
                out.print(intPageCount);
            // end
            // HTML // begin [file="/list.jsp";from=(66,33);to=(67,0)]
                out.write("页\r\n");

            // end
            // begin [file="/list.jsp";from=(67,2);to=(68,0)]
                if(intPage>1){
            // end
            // HTML // begin [file="/list.jsp";from=(68,2);to=(69,24)]
                out.write("\r\n <a href=\"list.jsp?page=");

            // end
            // begin [file="/list.jsp";from=(69,27);to=(69,36)]
                out.print(intPage-1);
            // end
            // HTML // begin [file="/list.jsp";from=(69,38);to=(70,0)]
                out.write("\">上一页</a>\r\n");

            // end
            // begin [file="/list.jsp";from=(70,2);to=(73,0)]
                
                }
                  if(intPage<intPageCount){
            // end
            // HTML // begin [file="/list.jsp";from=(73,2);to=(74,26)]
                out.write("\r\n  <a  href=\"list.jsp?page=");

            // end
            // begin [file="/list.jsp";from=(74,29);to=(74,38)]
                out.print(intPage+1);
            // end
            // HTML // begin [file="/list.jsp";from=(74,40);to=(75,0)]
                out.write("\">下一页</a>\r\n");

            // end
            // begin [file="/list.jsp";from=(75,2);to=(77,0)]
                
                }
            // end
            // HTML // begin [file="/list.jsp";from=(77,2);to=(83,0)]
                out.write("\r\n   转到第:<input type=\"text\" name=\"page\" size=\"2\"> 页 <input  type=\"submit\" value=\"GO\">\r\n</form>\r\n</body>\r\n</center>\r\n</html>\r\n");

            // end

        } catch (Throwable t) {
            if (out != null && out.getBufferSize() != 0)
                out.clearBuffer();
            if (pageContext != null) pageContext.handlePageException(t);
        } finally {
            if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -