all gone

          all gone

          JSP實現留言板的JavaBean類和分頁顯示的源碼

           

          //留言bean
          package userinfobean;

          /**
           * <p>Title: </p>
           * <p>Description: </p>
           * <p>Copyright: Copyright (c) 2004</p>
           * <p>Company: </p>
           * @author not attributable
           * @version 1.0
           */

          public class memoBean {

            private String id;//1.用戶名
            private String email;//2.密碼
            private String content;//3.留言 

            public memoBean() {
            }
            //1.用戶名
            public void setId(String s){
              this.id=s;
            }
            //2.密碼
            public void setEmail(String s){
              this.email=s;
            }
            //3.留言
             public void setContent(String s){
              this.content=s;
            }
           

            //1.用戶名
             public String getId( ){
               return this.id;
             }
             //2.密碼
             public String getEmail(){
               return this.email;
             }
             //3.留言 
             public String getContent(){
               return this.content;
             }
          }
          //// 用于數據庫操作的bean          
          package userinfobean;

          import userinfobean.*;
          import java.io.*;
          import java.util.*;
          import java.sql.*;


          public class databaseBean{
            private String dbName;
            private String dbUser;
            private String dbPass;
             private Vector memoVector;

             Connection connection;

            public databaseBean(){
              dbName=new String("×××××××");
              dbUser=new String("××××××");
              dbPass=new String("×××××××");
              String connectionUrl="jdbc:mysql://localhost/"+dbName;
              try{
                Class.forName("org.gjt.mm.mysql.Driver");
                connection=DriverManager.getConnection(connectionUrl,dbUser,dbPass);
              }
              catch(Exception e){
                System.out.println(e.toString());
                }
            }

            public void dbQueryMemos(){
              try{
                 memoVector=new Vector();
                Statement stmt=connection.createStatement();
                ResultSet rs=stmt.executeQuery("select * from memo;");
                while(rs.next()){
                  memoBean temp=new memoBean();
                  temp.setId(rs.getString(2));
                  temp.setEmail(rs.getString(3));
                  temp.setContent(rs.getString(4));
                  memoVector.add(temp);
                }

             }
             catch(SQLException e){
               System.out.println(e.toString());
             }

           

            }

              public void setDbName(String s){
              this.dbName=s;
            }
            public void setDbUser(String s){
              this.dbUser=s;
            }
            public void setDbPass(String s){
              this.dbPass=s;
            }

            public String getDbName(){
              return this.dbName;
            }
            public String getDbUser(){
              return this.dbUser;
            }
            public String getDbPass(){
              return this.dbPass;
            }
              public Vector getMemoVector(){
              return this.memoVector;

            }

          }

          ///以下是網頁源碼

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <%@ page language="java" import="java.util.*" %>
          <%@ page  import="java.text.*" %>
          <%@ page  import="userinfobean.*" %>
          <jsp:useBean id="memoInfo" scope="page" class="userinfobean.memoBean"/>
          <jsp:useBean id="memoQuery" scope="page" class="userinfobean.databaseBean"/>
          <%!
          int totalPages;
          int countPerPage=3;
          int totalCount;
          int currentPage=0;
          int currentStart;
          %>
          <%
          memoQuery.dbQueryMemos();
          Vector vt=memoQuery.getMemoVector();
          totalCount=vt.size();
          totalPages=totalCount/countPerPage;
          if(totalCount%countPerPage>0)totalPages=totalPages+1;
          if(request.getParameter("page")==null)
          {
          currentPage=1;
          }
          else
          {
          currentPage=Integer.parseInt(request.getParameter("page"));
          if(currentPage>totalPages)currentPage=totalPages;
          if(currentPage<1)currentPage=1;
          }
          currentStart=totalCount-1-countPerPage * (currentPage-1);
          %>
          <html>
          <head>
          <title>NetGreen</title>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
            <link rel="stylesheet" href="main.css">                            
          </head>
          <script language="JavaScript" >
          function page_check()
          {
          if(document.pageForm.page.value=="")
          {alert("請輸入頁數");
          document.pageForm.page.focus();
          return false;
          }
          return true;
          }</script>
          <body bgcolor="ffffff"  >

          <center>
            <table width="800" border="0" height="622">
              <tr>
                <td height="71" align="center" valign="middle"> <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#0099CC">
                    <tr>
                      <td width="19%" height="60" align="left" valign="bottom" bgcolor="#FFFFFF"><b><font size="4" color="#00cc66" ><img src="image/logo.gif" width="156" height="60"></font></b></td>
                      <td width="57%" align="left" valign="bottom" bgcolor="#FFFFFF"><img src="image/banner.gif" width="100%" height="60"></td>
                      <td width="24%" align="left" valign="bottom"> <table width="102%" height="60" border="1" cellpadding="0" cellspacing="0" bordercolor="#0099CC" bgcolor="#FFFFFF">
                          <tr>
                            <td width="50%" height="27" align="center">上 傳</td>
                            <td width="50%" align="center">收藏本頁</td>
                          </tr>
                          <tr>
                            <td height="21" align="center" bgcolor="#FFFFFF" >退 出 </td>
                            <td align="center"><a href="memoForm.htm" target="_self">我要留言</a></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table></td>
              </tr>
              <tr>
                <td height="31"><table width="100%" border="1" bordercolor="#0099CC">
                    <tr bgcolor="#00CC66">
                      <td width="12%" height="23" align="center" bgcolor="#CCFFFF"><a href="index.htm" >首頁</a></td>
                      <td width="12%" align="center" bgcolor="#CCFFFF"><a href="loginForm.htm" >登陸</a></td>
                      <td width="12%" align="center" bgcolor="#CCFFFF">&nbsp;</td>
                      <td width="12%" align="center" bgcolor="#CCFFFF">&nbsp;</td>
                      <td width="12%" align="center" bgcolor="#CCFFFF" >&nbsp; </td>
                      <td width="12%" align="center" bgcolor="#CCFFFF">&nbsp;</td>
                      <td width="12%" align="center" bgcolor="#CCFFFF"><a href="memoDisplay.jsp" >留言板</a></td>
                      <td width="12%" align="center"  bgcolor="#CCFFFF"><a href="registForm.htm">注冊</a></td>
                    </tr>
                  </table></td>
              </tr>
              <tr>
                <td height="435" align="center" valign="top" nowrap>
                  <table width="100%"  border="1" cellpadding="0" cellspacing="0" bordercolor="#0099CC">
                    <tr>
                      <td width="18%" height="431" align="center" valign="middle" bgcolor="#CCFFFF">
                      </td>
                      <td width="83%" align="center" valign="top" bgcolor="#FFFFFF"><table width="100%" border="1"><form name="pageForm" method="post"  onSubmit="return page_check();"action="memoDisplay.jsp">
                          <tr>
                            <td width="36%">共有留言<%out.print(totalPages);%> 頁,現在是第<%out.print(currentPage);%>  頁</td>
                              <td width="64%">
               <a href="memoDisplay.jsp?page=<%=currentPage-1%>" >上一頁 </a>
               <a href="memoDisplay.jsp?page=<%=currentPage+1%>" >下一頁  </a>
               <a href="memoDisplay.jsp?page=1" >首頁 </a>
                <a href="memoDisplay.jsp?page=<%=totalPages%>" >尾頁  </a>
                <input type="submit" name="Submit" value="G0">
                                <input name="page" type="text" size="10">
                                頁</td>
                          </tr>
                        </form></table>
                        <%
              
              for(int i=0;i<countPerPage&&currentStart-i>=0;i++)
              {
               memoInfo.setId(((memoBean)vt.get(currentStart-i)).getId());
               memoInfo.setEmail(((memoBean)vt.get(currentStart-i)).getEmail());
               memoInfo.setContent(((memoBean)vt.get(currentStart-i)).getContent());
               
               
               
             out.print("<table width='100%' border='1' ><tr><td width='19%'>");
             out.print(memoInfo.getId());
             out.print("</td><td width='81%'>");
             out.print(memoInfo.getEmail());
             out.print("</td></tr><tr><td height='44' colspan='2'>");
             out.print(memoInfo.getContent());
             out.print("</td></tr></table> ");
             out.print("<br>");
               
              }
            
             %>
             </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td height="73" align="center" valign="top" nowrap>
                  <table width="100%" border="0">
                    <tr>
                      <td height="21" align="center" bgcolor="#FFFFFF"><hr width="85%" noshade  color="#00CC66"></td>
                    </tr>
                    <tr>
                      <td height="12" align="center">Copyright @ HomeLee. All rights reserved.
                      </td>
                    </tr>
                    <tr>
                      <td height="12" align="center" bgcolor="#FFFFFF">&nbsp;</td>
                    </tr>
                  </table></td>
              </tr>
            </table>
            </center></body>
          </html>

          posted on 2005-12-09 19:30 all gone 閱讀(519) 評論(1)  編輯  收藏 所屬分類: Java

          評論

          # re: JSP實現留言板的JavaBean類和分頁顯示的源碼 2007-06-22 09:43 fds

          不錯,學習  回復  更多評論   

          主站蜘蛛池模板: 柏乡县| 逊克县| 柳江县| 聂拉木县| 夏津县| 武鸣县| 堆龙德庆县| 石渠县| 宜昌市| 偃师市| 周宁县| 凉山| 增城市| 龙泉市| 阿拉善右旗| 怀安县| 扶风县| 永吉县| 成都市| 固安县| 南城县| 美姑县| 常熟市| 沙坪坝区| 休宁县| 金昌市| 定州市| 花垣县| 内江市| 波密县| 昌吉市| 玛曲县| 桃园市| 贵德县| 宜兰市| 邻水| 长岛县| 阿巴嘎旗| 桃园市| 乐昌市| 庆元县|