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

📄 fy_0002ejsp_jsp.java

📁 j2ee servlet 分页实例
💻 JAVA
字号:
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;


public class fy_0002ejsp_jsp extends HttpJspBase {


    static {
    }
    public fy_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="/fy.jsp";from=(0,48);to=(8,0)]
                out.write("\r\n<html>\r\n<head>\r\n<title>\r\nfy\r\n</title>\r\n</head>\r\n<body bgcolor=\"#ffffff\">\r\n");

            // end
            // begin [file="/fy.jsp";from=(8,2);to=(49,0)]
                
                java.sql.Connection con = null;
                java.sql.Statement stmt = null;
                java.sql.ResultSet rs = null;
                String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
                String sql = "SELECT au_id,au_lname,au_fname FROM authors";
                java.util.ArrayList data = new java.util.ArrayList();
                java.util.ArrayList cell = null;
                try{
                Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                con = java.sql.DriverManager.getConnection(url,"sa","qaz123");
                stmt = con.createStatement();
                rs = stmt.executeQuery(sql);
                while(rs.next()){
                cell = new java.util.ArrayList();
                cell.add(rs.getString("au_id"));
                cell.add(rs.getString("au_lname"));
                cell.add(rs.getString("au_fname"));
                data.add(cell);
                }
                rs.close();
                stmt.close();
                con.close();
                }catch(Exception e){
                System.out.println(e.getMessage());
                }
                ////////////////////////////////////////////////
                int pageCount = 10;
                int pageNow = 1;
                int startNum = 0;
                int endNum = 0;
                ///////////////////////////////
                if(request.getParameter("page") != null){
                pageNow = Integer.parseInt(request.getParameter("page"));
                }
                startNum = (pageNow-1)*pageCount;
                endNum = startNum + pageCount;
                if(endNum >= data.size()){
                endNum = data.size();
                }
                ////////////////////////////////
            // end
            // HTML // begin [file="/fy.jsp";from=(49,2);to=(57,0)]
                out.write("\r\n<h1>\r\n<table border=\"1\" width=\"51%\">\r\n  <tr>\r\n    <td width=\"33%\" align=\"center\">id</td>\r\n    <td width=\"33%\" align=\"center\">first</td>\r\n    <td width=\"34%\" align=\"center\">last</td>\r\n  </tr>\r\n");

            // end
            // begin [file="/fy.jsp";from=(57,2);to=(60,0)]
                
                for(int i = startNum;i < endNum;i++){
                java.util.ArrayList row = (java.util.ArrayList)data.get(i);
            // end
            // HTML // begin [file="/fy.jsp";from=(60,2);to=(62,35)]
                out.write("\r\n  <tr>\r\n    <td width=\"33%\" align=\"center\">");

            // end
            // begin [file="/fy.jsp";from=(62,38);to=(62,49)]
                out.print( row.get(0));
            // end
            // HTML // begin [file="/fy.jsp";from=(62,51);to=(63,35)]
                out.write("</td>\r\n    <td width=\"33%\" align=\"center\">");

            // end
            // begin [file="/fy.jsp";from=(63,38);to=(63,49)]
                out.print( row.get(1));
            // end
            // HTML // begin [file="/fy.jsp";from=(63,51);to=(64,35)]
                out.write("</td>\r\n    <td width=\"34%\" align=\"center\">");

            // end
            // begin [file="/fy.jsp";from=(64,38);to=(64,49)]
                out.print( row.get(2));
            // end
            // HTML // begin [file="/fy.jsp";from=(64,51);to=(66,0)]
                out.write("</td>\r\n  </tr>\r\n");

            // end
            // begin [file="/fy.jsp";from=(66,2);to=(68,0)]
                
                }
            // end
            // HTML // begin [file="/fy.jsp";from=(68,2);to=(70,21)]
                out.write("\r\n</table>\r\n<a href='fy.jsp?page=");

            // end
            // begin [file="/fy.jsp";from=(70,24);to=(70,34)]
                out.print( pageNow-1);
            // end
            // HTML // begin [file="/fy.jsp";from=(70,36);to=(71,21)]
                out.write("'>上一页</a><br>\r\n<a href='fy.jsp?page=");

            // end
            // begin [file="/fy.jsp";from=(71,24);to=(71,34)]
                out.print( pageNow+1);
            // end
            // HTML // begin [file="/fy.jsp";from=(71,36);to=(75,0)]
                out.write("'>下一页</a><br>\r\n</h1>\r\n</body>\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 + -