分享
 
 
 

GuestBook Test

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

这是我的第一个留言板测试例子,包括登陆界面,留言板主页,添加留言等页面:

1.页面

F:\Tomcat 5.0\webapps\ROOT\login

log.html

log_cm.jsp

success.jsp

relog.jsp

index.jsp

guestbook.jsp

2.Bean

F:\Tomcat 5.0\webapps\ROOT\WEB-INF\classes\login

LogBean.java

3.数据库

F:\Tomcat 5.0\webapps\ROOT\BUSINESS(BUSINESS 是可以自定义的)

firm.mdb——两个表:

user(name,password,email);

guest(未完成,用作保存留言.....)

4.表情

F:\Tomcat 5.0\webapps\ROOT\images

hello.gif

...

1。log.html

<html>

<head>

<title>我的第一个HTML登陆界面</title>

<meta http-equiv = "Content-Type" content = "text/html; charset = gb2312" >

<style type = "text/css">

body { font-family:宋体; font-size:9pt}

th { font-size: 9pt }

</style>

</head>

<body>

<center>

<table border = "0" cellspacing = "0" width = "332" bgcolor = "#F0F8FF"

bordercolorlight = "#4DA6FF" bordercolordark = "#ECF5FF">

<tr><td colspan=2 align='center'><h4>请你登陆:</h4></td></tr>

<form method = post action = "log_cm.jsp">

<tr>

<td align='left'>用户名:</td>

<td><input type="text" name="username"></td>

</tr>

<tr>

<td align='left'>密&nbsp;&nbsp;码:</td>

<td><input type="password" name="password"></td>

</tr>

<tr>

<td align='left'>邮&nbsp;&nbsp;箱:</td>

<td><input type="text" name="email"></td>

</tr>

<tr>

<td colspan=2 align='center'>

<input type="submit" size="4" value="确定">

<input type="reset" size="4" value="重置">

</td>

</tr>

</form>

</table>

</center>

</body>

</html>

2。log_cm.jsp

<%-- class="login.LogBean" 指代\ROOT\WEB-INF\classes\login 目录下的LogBean 类 --%>

<jsp:useBean id="handle" class="login.LogBean" scope="request">

<jsp:setProperty name="handle" property="*"/>

</jsp:useBean>

<html>

<head><title>验证界面</title></head>

<body>

<%-- session.putValue("loginsign", "ok"); 用于检验用户是否已经登陆 --%>

<%

session.putValue("loginsign", "ok");

if(handle.validate()){

%>

<jsp:forward page="success.jsp"/>

<%

}

if(!handle.validate()){

%>

<jsp:forward page="relog.jsp"/>

<%

session.putValue("loginsign", "false");

}

%>

</body>

</html>

3。success.jsp

<%-- class="login.LogBean" 指代\ROOT\WEB-INF\classes\login 目录下的LogBean 类 --%>

<jsp:useBean id="handle" class="login.LogBean" scope="request"/>

<jsp:useBean id="addBean" class="dbtest.Accessdb" scope="page"/>

<html>

<head>

<title>注册成功</title>

<meta http-equiv = "Content-Type" content = "text/html; charset = gb2312" >

<style type = "text/css">

body { font-family:宋体; font-size:9pt}

th { font-size: 9pt }

td { font-size: 9pt }

</style>

</head>

<body>

<center>

<table border = "0" cellspacing = "0" width = "332" bgcolor = "#F0F8FF"

bordercolorlight = "#4DA6FF" bordercolordark = "#ECF5FF">

<tr><td colspan=2 align='center'><h4>祝贺你注册成功!</h4></td></tr>

<tr>

<td align='left'>用户名:</td>

<td><jsp:getProperty name="handle" property="username"/></td>

</tr>

<tr>

<td align='left'>密&nbsp;&nbsp;码:</td>

<td><jsp:getProperty name="handle" property="password"/></td>

</tr>

<tr>

<td align='left'>邮&nbsp;&nbsp;箱:</td>

<td><jsp:getProperty name="handle" property="email"/></td>

</tr>

</table>

<%

//把"8859_1"码转换为"gb2312"码

String name = new String(handle.getUsername().getBytes("8859_1"));

String password = new String(handle.getPassword().getBytes("8859_1"));

String email = new String(handle.getEmail().getBytes("8859_1"));

String strSQL = " insert into user(name, password, email) values(' "

+ name + " ',' " + password + " ',' " + email + " ') "; //把记录写入数据库

addBean.executeUpdate(strSQL);

out.print("你的留言已经保存到数据库中,谢谢!");

%>

</center>

</body>

</html>

4。relog.jsp

<jsp:useBean id="handle" class="login.LogBean" scope="request"/>

<html>

<head>

<title>重新登陆</title>

<meta http-equiv = "Content-Type" content = "text/html; charset = gb2312" >

<style type = "text/css">

body { font-family:宋体; font-size:9pt}

th { font-size: 9pt }

</style>

</head>

<body>

<form method = post action = "log_cm.jsp">

<table border = "0" cellspacing = "0" width = "332" bgcolor = "#F0F8FF"

bordercolorlight = "#4DA6FF" bordercolordark = "#ECF5FF">

<tr><td colspan=2 align='center'><h4>请重新登陆:</h4></td></tr>

<tr>

<td align='left'>用户名:</td>

<td><input type="text" name="username"

value="<jsp:getProperty name="handle" property="username"/>">

</td>

</tr>

<tr>

<td align='left'>密&nbsp;&nbsp;码:</td>

<td><input type="password" name="password"

value="<jsp:getProperty name="handle" property="password"/>">

<%=handle.getErrorMsg("password")%>

</td>

</tr>

<tr>

<td align='left'>邮&nbsp;&nbsp;箱:</td>

<td><input type="text" name="email"

value="<jsp:getProperty name="handle" property="email"/>">

<span class="error"><%=handle.getErrorMsg("email")%></span>

</td>

</tr>

<tr>

<td colspan=2 align='center'>

<input type="submit" size="4" value="确定">

<input type="reset" size="4" value="重置">

</td>

</tr>

</table>

</form>

</body>

</html>

5。index.jsp

<%@ page contentType="text/html; charset=gb2312"%>

<%@ page import="java.sql.*" %>

<jsp:useBean id="showBean" scope="page" class="dbtest.Accessdb" />

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>我的第一个留言板主页</title>

<link rel=stylesheet href="../style.css" type="text/css">

</head>

<body>

<script language="javascript">

function submit(){

self.location.replace("index.jsp")

}

</script>

<center><p>留言板</p>

<table>

<tr>

<td>

<p align='left'>&gt;&gt;分页&nbsp;

<a href='guestbook.jsp'>我要留言</a>&nbsp;

</td>

</tr>

</table>

<%

//指定行数

int pageLine = 10;

int totalRec = 0;

int totalSub = 0;

int intPage = 1;

int i;

try{

ResultSet rs = null;

//取得总记录数

rs = showBean.executeQuery("select count(*) as cnt from guestbook");

if( rs.next() )

totalRec = rs.getInt("cnt");

rs.close();

showBean.closeStat();

}catch(Exception e){ e.printStackTrace(); }

//取得总页数

int intPageCount = 0;

intPageCount = (totalRec + pageLine - 1) / pageLine ;

ResultSet RS = showBean.executeQuery("select * from guestbook order by serial_no desc");

String emote1;

String name1;

Date gtime1;

String content1;

%>

<table border='1' cellspacing='0' width="80%" bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ecf5ff'>

<tr align='center'>

<td>表情</td>

<td>留言人</td>

<td>留言时间</td>

<td>留言内容</td>

</tr>

<%

if(intPageCount>0){

for(i=1; i<(intPage-1)*pageLine; i++)

RS.next();

for(i=1; i<=pageLine; i++) {

if(RS.next()){

emote1 = RS.getString("emote");

name1 = RS.getString("name");

gtime1 = RS.getDate("guest_time");

content1 = RS.getString("content");

%>

<tr>

<td align='center'><img src="../images/<%=emote1%>.gif" ></td>

<td align='center'><%=name1%></td>

<td align='center'><%=gtime1%></td>

<td align='center'><%=content1%></td>

</tr>

<%

}//if(RS.next())

}//for(i=1; i<=pageLine; i++)

RS.close();

}//if(intPageCount>0)

%>

<!--以下用于留言分页显示-->

</table>

</center>

</body>

</html>

6。guestbook.jsp

<html>

<head>

<title>我的第一个GUESTBOOK</title>

<link rel = stylesheet href="../style.css" type="text/css">

<script language="JavaScript">

function valiform() {

if(document.form1.content.value=""){

alert("留言内容不能为空!");

documnet.form1.content.focus();

return false;

}

}

</script>

</head>

<body>

<form method=post action="ok_guestbook.jsp" name=form1 onSubmit="return valiform()">

<center><h4></font color="blue">留言</font></h4></p>

<table width='60%' height='120'>

<%-- 取得用户登陆时的session 变量值,并存放在隐藏域中 --%>

<%String name1 = (String)session.getValue("username");%>

<input type="hidden" name="name" value=<%=name1%>>

<tr>

<td>留言人:<%=name1%></td>

</tr>

<tr>

<td>表&nbsp;&nbsp;情:

<select name="emote" size="1">

<option style="color: #000000" value="p1" selected>大家好</option>

<option style="color: #000000" value="p2" >赞成</option>

<option style="color: #000000" value="p3" >反对</option>

<option style="color: #000000" value="p4" >不太明白</option>

</select>

</td>

</tr>

<tr>

<td>留&nbsp;&nbsp;言:<br>

<textarea name="content" cols="50" rows="10" maxlength="80"></textarea>

</td>

</tr>

<tr>

<td align="center">

<input type="submit" size="4" value="提交" class="buttonface">&nbsp;&nbsp;

<input type="reset" size="4" value="重写" class="buttonface">

</td>

</tr>

</table>

</center>

</form>

</body>

</html>

7。LogBean.java

package login;

import java.util.*;

public class LogBean

{

private String username;

private String password;

private String email;

private Hashtable errors;

public LogBean(){

username = "";

password = "";

email = "";

errors = new Hashtable();

}

public String getUsername(){

return username;

}

public String getPassword(){

return password;

}

public String getEmail(){

return email;

}

public void setUsername(String usernameStr){

username = usernameStr;

}

public void setPassword(String passwordStr){

password = passwordStr;

}

public void setEmail(String emailStr){

email = emailStr;

}

public void setErrors(String Key,String msg){

errors.put(Key,msg);

}

public boolean validate(){

boolean allOk = true;

if(username.equals("")){

errors.put("username","Plz enter your name");

username = "";

allOk = false;

}

if( (password.equals(""))||(password.length()>10)||(password.length()<6) ){

errors.put("password","Plz enter a password of 6-10 charactors.");

allOk = false;

}

if( (email.equals(""))||(email.indexOf('@')==-1)||(email.indexOf('.')==-1) ){

errors.put("email","Plz enter a valid Email");

allOk = false;

}

return allOk;

}

public String getErrorMsg(String s){

String errorMsg = (String) errors.get(s.trim());

return (errorMsg==null)?"":errorMsg;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
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- 王朝網路 版權所有