分享
 
 
 

JSP实现留言板的JavaBean类和分页显示的源码

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

//留言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>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有