• [BBS] ShowArticleFlat.jsp 08 、下拉条


    1 BBS
    <%@ page language="java" contentType="text/html; charset=gbk"
        pageEncoding="gbk"%>
    <%@ page import="java.sql.*"%>
    
    
    <%
        int pageSize = 3;
    
        String strPageNo = request.getParameter("pageNo");
        int pageNo;
        if (strPageNo == null || strPageNo.equals("")) {
            pageNo = 1;
        } else {
            try {
                pageNo = Integer.parseInt(strPageNo.trim());
            } catch (NumberFormatException e) {
                pageNo = 1;
            }
            if (pageNo <= 0)
                pageNo = 1;
        }
    
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
        Connection conn = DriverManager.getConnection(url);
    
        Statement stmtCount = conn.createStatement();
        ResultSet rsCount = stmtCount
                .executeQuery("select count(*) from article where pid = 0");
        rsCount.next();
        int totalRecords = rsCount.getInt(1);
    
        int totalPages = totalRecords % pageSize == 0 ? totalRecords
                / pageSize : totalRecords / pageSize + 1;
        if (pageNo > totalPages)
            pageNo = totalPages;
    
        int startPos = (pageNo - 1) * pageSize;
    
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt
                .executeQuery("select * from article where pid = 0 order by pdate desc limit "
                        + startPos + "," + pageSize);
    %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title>Insert title here</title>
    </head>
    <body>
        <a href="Post.jsp">发表新帖</a>
    
        <table border="1">
    
            <%
                while (rs.next()) {
            %>
            <tr>
                <td><%=rs.getString("title")%></td>
            </tr>
            <%
                }
                rs.close();
                stmt.close();
                conn.close();
            %>
        </table>
    
        共<%=totalPages%>页 第<%=pageNo%>页
        <a href="ShowArticleFlat.jsp?pageNo=<%=pageNo - 1%>"> < </a>
            
        <a href="ShowArticleFlat.jsp?pageNo=<%=pageNo + 1%>"> > </a>
    
        <form name="form1" action="ShowArticleFlat.jsp">
            <select name="pageNo" onchange="document.form1.submit()">
                <%
                    for (int i = 1; i <= totalPages; i++) {  // 下拉条
                %>
                <option value=<%=i%> <%=(pageNo == i) ? "selected" : ""%>>
                    第<%=i%>页
                    <%
                    }
                %>
                
            </select>
        </form>
    
        <form name="fom2" action="ShowArticleFlat.jsp">
            <input type=text size=4 name="pageNo" value=<%=pageNo%> /> <input
                type="submit" value="go" />
        </form>
    
    </body>
    
    </html>
    

  • 相关阅读:
    Base64原理与实现
    Oracle中rownum用法警示
    实例游戏内存修改器----CUI版本模拟
    Win32进程创建、进程快照、进程终止用例
    pThreads线程(三) 线程同步--条件变量
    pThreads线程(二) 线程同步--互斥量/锁
    pThreads线程(一) 基本API
    VS调试快捷键
    运行程序报“应用程序配置不正确”或者缺少运行库造成程序不可移植的问题
    C++模拟键盘消息
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786844.html
Copyright © 2020-2023  润新知