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

📄 comment.jsp

📁 一个简单实用的网上书城,可当作原型使用
💻 JSP
字号:
<%@ page contentType="text/html"%><%@ page  pageEncoding="gb2312"%> <%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %><jsp:useBean class="czm.BookBean" id="bookinfo" scope="page"></jsp:useBean><jsp:useBean class="czm.Comment" id="comm" scope="page"></jsp:useBean><html><head>        <title>网上书城留言评论</title></head><body>       <%	        if (session.getValue("memberID") == null||"".equals(session.getValue("memberID"))){    %>            <H2 align="center">请先登录</H2>            <H2 align="center"><A href="default.html">登录</A></H2>    <%        }else{             if (request.getParameter("ISBN")!=null && !request.getParameter("ISBN").equals("")){	                    String isbn = request.getParameter("ISBN");                    bookinfo.setBookISBN(isbn);            %>                       <blockquote>                        <H2 class="STYLE1" align="center">欢迎访问<%= bookinfo.getBookName()%>的评论</H2>                    </blockquote>                                        <div align="center"><A href="booklist.jsp">返回图书首页</A><br><br>                        <%	                        ResultSet rs = comm.BrowseComment(bookinfo.getBookISBN());                        //移动游标至结果集的最后一行。                        rs.last();                        //得到当前行的行数,也就得到了数据库中留言的总数。                        int rowCount=rs.getRow();                        //表示当前的页数。                        int curPage=1;                        //定义每页显示的留言数。                        int countPerPage=10;                        int pageCount=0;                                if(rowCount==0)                        {                                out.println("当前没有任何评论!");                                //return;                        }else{                               String strCurPage=request.getParameter("page");                               if(strCurPage==null)                                    curPage=1;                                else                                    curPage=Integer.parseInt(strCurPage);                                //计算显示所有留言需要的总页数。                                pageCount=(rowCount+countPerPage-1)/countPerPage;                                //移动游标至结果集中指定的行。如果显示的是第一页,curPage=1,                                //游标移动到第1行。                                rs.absolute((curPage-1)*countPerPage+1);                                out.println("共"+rowCount+"条评论");                                %>                                &nbsp;&nbsp;&nbsp;&nbsp;                                <%                                //如果是第1页,则显示不带链接的文字,如果不是第1页,                                //则给用户提供跳转到第一页和上一页的链接。                                                                if(curPage==1){                                 %>                                        首页&nbsp;&nbsp;&nbsp;&nbsp;                                        上一页&nbsp;&nbsp;&nbsp;&nbsp;                                <%                                }else {                                %>                                    <a href="comment.jsp?ISBN=<%= bookinfo.getBookISBN()%>&page=<%=1%>">首页</a>                                    &nbsp;&nbsp;&nbsp;&nbsp;                                    <a href="comment.jsp?ISBN=<%= bookinfo.getBookISBN()%>&page=<%=curPage-1%>">上一页</a>                                    &nbsp;&nbsp;&nbsp;&nbsp;                                <%                                }                                //如果当前页是最后一页,则显示不带链接的文字,如果不是最后一页,                                //则给用户提供跳转到最后一页和下一页的链接。                                if(curPage==pageCount)                                {                                %>                                        下一页&nbsp;&nbsp;&nbsp;&nbsp;                                        尾页&nbsp;&nbsp;&nbsp;&nbsp;                                <%                                }else{                                %>                                        <a href="comment.jsp?ISBN=<%= bookinfo.getBookISBN()%>&page=<%=curPage+1%>">下一页</a>                                        &nbsp;&nbsp;&nbsp;&nbsp;                                        <a href="comment.jsp?ISBN=<%= bookinfo.getBookISBN()%>&page=<%=pageCount%>">尾页</a>                                        &nbsp;&nbsp;&nbsp;&nbsp;                                <%                                }                                out.println("页次: "+curPage+"/"+pageCount+"页");                                %>                          <table width="600" border="1" cellpadding="0" cellspacing="2">                                <%                                int i=0;                                //以循环的方式取出每页要显示的数据,因为在前面针对要显示的页数,                                //调用了rs.absolute((curPage-1)*countPerPage+1);                                //所以是从游标所在的位置取出当前页要显示的数据。                                while(i<countPerPage && !rs.isAfterLast())                                {                                    //String commdate = rs.getString("commentDate");                                %>                                <tr bgcolor="orange">                                    <td height="25" width="100">会员:<%=rs.getString("memberID")%></td>                                    <td height="25" width="500">发表时间:<%=rs.getString("commentDate")%>&nbsp;&nbsp;&nbsp;&nbsp;IP:<%=rs.getString("memberIP")%></td>                                </tr>                                    <tr bgcolor="#FFFFFF">                                        <td height="25" width="100"><font color="#000FFF">主题:</font></td>                                        <td height="25" width="500"><font color="#000000"><%=rs.getString("commentTitle")%></font></td>                                    </tr>                                    <tr bgcolor="#FFFFFF">                                        <td height="25" width="100"><font color="#000FFF">内容:</font></td>                                        <td height="25" width="500"><font color="#000000"><%=rs.getString("comment")%></font></td>                                    </tr>                               <%                                                           i++;                                    rs.next();                                 }                                rs.close();                                       %>                          </table>                                <%                                 out.println("共"+rowCount+"条评论");                                %>                                &nbsp;&nbsp;&nbsp;&nbsp;                                <%                                //如果是第1页,则显示不带链接的文字,如果不是第1页,                                //则给用户提供跳转到第一页和上一页的链接。                                if(curPage==1)                                {                                 %>                                        首页&nbsp;&nbsp;&nbsp;&nbsp;                                        上一页&nbsp;&nbsp;&nbsp;&nbsp;                                <%                                }else{                                %>                                    <a href="comment.jsp?ISBN=<%= bookinfo.getBookISBN()%>&page=<%=1%>">首页</a>                                    &nbsp;&nbsp;&nbsp;&nbsp;                                    <a href="comment.jsp?ISBN=<%= bookinfo.getBookISBN()%>&page=<%=curPage-1%>">上一页</a>                                    &nbsp;&nbsp;&nbsp;&nbsp;                                <%                                }                                //如果当前页是最后一页,则显示不带链接的文字,如果不是最后一页,                                //则给用户提供跳转到最后一页和下一页的链接。                                if(curPage==pageCount)                                {                                %>                                        下一页&nbsp;&nbsp;&nbsp;&nbsp;                                        尾页&nbsp;&nbsp;&nbsp;&nbsp;                                <%                                }else{                                %>                                        <a href="comment.jsp?ISBN=<%= bookinfo.getBookISBN()%>&page=<%=curPage+1%>">下一页</a>                                        &nbsp;&nbsp;&nbsp;&nbsp;                                        <a href="comment.jsp?ISBN=<%= bookinfo.getBookISBN()%>&page=<%=pageCount%>">尾页</a>                                        &nbsp;&nbsp;&nbsp;&nbsp;                            <%                                }                                out.println("页次: "+curPage+"/"+pageCount+"页");                             }                            %>                    </div>                    <center>                      <form action="preComment.jsp" method="post">                        <table bgcolor="orange">                              <caption>欢迎访问<%= bookinfo.getBookName()%>的评论</caption>                        <tr>                        <td>会员ID:</td>                        <td><input type="text" name="name" readonly value="<%= session.getValue("memberID") %>"></td>                        </tr>                        <tr>                        <td>ISBN号:</td>                        <td><input type="text" name="isbn" readonly value="<%= bookinfo.getBookISBN()%>"></td>                        </tr>                        <tr>                        <td>主题:</td>                        <td><input type="text" name="title" value="<%= bookinfo.getBookName()%>的评论"></td>                        </tr>                        <tr>                        <td>内容:</td>                        <td>                        <textarea name="content" rows="6" cols="72"></textarea>                        </td>                        </tr>                        <tr>                        <td><input type="submit" value="提交"></td>                        <td><input type="reset" value="重填"></td>                        </tr>                        </table>                      </form>                  </center>         <%             }else{         %>                 <blockquote>                    <H2 class="STYLE1" align="center">请指定图书!</H2>                    <H2 align="center"><A href="booklist.jsp">返回</A></H2>                </blockquote>         <%             }         }         %></body></html>

⌨️ 快捷键说明

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