GuestBook Test[1]

[入库:2005年8月19日] [更新:2007年3月25日]

本文简介:选择自 milan25429688 的 blog

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

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

本文关键:GuestBook Test
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top