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

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

F:/Tomcat 5.0/webapps/ROOT/WEB-INF/classes/dbtest
Accessdb.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;
  }
 
}

8。Accessdb.java

package dbtest;

//1.导入JDBC 标准类库
import java.sql.*;

public class Accessdb {
  String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
  String sConnStr = "jdbc:odbc:firm";
  private Connection con = null;
  private Statement stat = null;
  ResultSet rs = null;
 
  //2.注册数据库驱动程序
  public Accessdb()
  {
    try{
      Class.forName(sDBDriver);
    }
    catch(java.lang.ClassNotFoundException e){
      System.err.println("firm():" + e.getMessage());
    }
  }
 
  //3.建立数据库连接及定义数据查询
  public ResultSet executeQuery(String sql){
    rs = null;
    try{
      con = DriverManager.getConnection(sConnStr);
      stat = con.createStatement();
      rs = stat.executeQuery(sql);
    }
    catch(SQLException ex){
      System.err.println("aq.executeQuery:" + ex.getMessage());
    }
    return rs;
  }
 
  //4.定义数据操作
  public void executeUpdate(String sql){
    stat = null;
    rs = null;
    try{
      con = DriverManager.getConnection(sConnStr);
      stat = con.createStatement();
      stat.executeQuery(sql);
      stat.close();
      con.close();
    }
    catch(SQLException ex){
      System.err.println("aq.executeQuery:" + ex.getMessage());
    }
  }
 
  //5.关闭数据库连接
  public void closeStat(){
    try{
      stat.close();
    }
    catch(SQLException e){
      e.printStackTrace();
    }
  }
 
  public void closeCon(){
    try{
      con.close();
    }
    catch(SQLException e){
      e.printStackTrace();
    }
  }
}

GuestBook Test相关推荐

  1. 开源 java CMS - FreeCMS2.8 数据对象 guestbook

    2019独角兽企业重金招聘Python工程师标准>>> 项目地址:http://www.freeteam.cn/ ​​​​​​​guestbook 在使用留言相关标签时,标签会封装g ...

  2. 织梦guestbook.php漏洞,DEDE:织梦漏洞修复(含任意文件上传漏洞与注入漏洞)

    这几天阿里频繁提醒网站有漏洞,搞得我不胜其烦,好吧,我修复还不行吗?搜索之后整理如下,仅供参考(5.7以上版本适用): 任意文件上传漏洞修复 一./include/dialog/select_soft ...

  3. YAML基础知识及搭建一台简洁版guestbook

    一,前言 前面我们已经搭建过简易版k8s集群了,在此基础上可以搭建一个简洁版guestbook ,以便来学习k8s创建pod的整个过程. 二,在此之前,我们还需要学习一下YAML基础知识 YAML 基 ...

  4. 织梦留言板guestbook.htm加入头部导航

    织梦仿站的时候如果有留言板,通常都是不像织梦这样的留言板独立的页面:都是带头部导航的.那么如何在guestbook.htm加入头部导航:如果直接加入head.htm的话.标签在这里是无法调用的:我们必 ...

  5. 华为云云容器快速搭建网站实践随记—利用私有镜像搭建GuestBook

    一.华为云云容器简单介绍: 云容器引擎 CCE 是基于 K8S 和 Docker 的企业级容器服务,为企业应用提供快速部署.自动化运维.弹性伸缩等容器生命周期管理能力. 这个实践是通过 docker ...

  6. (SAE)skylark app engine preview (1) —— guestbook

    感谢dc 为 skylark 设计 相当有趣的logo. 他是一个可爱的小云雀,他的追求简单的概括为--"design in GAE , fly everywhere " . [i ...

  7. 开源 免费 java CMS - FreeCMS1.5-数据对象-guestbook

    下载地址:http://code.google.com/p/freecms/ guestbook 从FreeCMS 1.5 开始支持 在使用留言相关标签时,标签会封装guestbook供页面调用. 属 ...

  8. CREATE DATABASE guestbook DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

    CREATE DATABASE `guestbook` DEFAULT CHARSET utf8 COLLATE utf8_general_ci; CREATE DATABASE guestbook ...

  9. guestbook.php注入,php防注入留言板(simple)

    新手学php,试手案例便是留言板.以前未连接数据库时,我是直接将用户输入的留言写入到一个txt,然后再从txt读取显示(~.~别鄙视). 最近学习了php访问MySQL数据库的一些知识,重写了一下留言 ...

最新文章

  1. kwargs.pop是什么意思
  2. python是用c写的吗-python和c语言的区别是什么
  3. android ViewPager页面左右滑动切换
  4. PAT甲级1058 A+B in Hogwarts :[C++题解]字符串,进制,简单
  5. html火影忍者网页设计作品,纯css3制作的火影忍者写轮眼开眼至轮回眼及进化过程实例...
  6. 波兰加密矿企GamerHash计划在韩国建立业务
  7. 昨天食物中毒,至今浑身酸痛
  8. datatable的数据进行组内排序_Spark实现分组Top-k排序的四种方案(scala语言)
  9. 爬虫单个ip代理设置_代理IP是怎么帮助爬虫持续工作的
  10. Odoo免费开源MES功能应用简介
  11. 苹果群控的安装和使用
  12. 电梯门禁系统服务器一般在哪,电梯控制系统与门禁系统的区别
  13. HTML小技巧的一些小技巧
  14. 【JDK源码剖析】Queue--队列 PriorityQueue--优先队列
  15. LCD1602液晶使用介绍--(完整版)
  16. 管理Chromium源代码的利器——depot_tools
  17. Windows~~~在MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES) ,并修改MySQL密码
  18. Qt项目中,绘制只有两个圆角的矩形及QPainterPath类的应用
  19. mysql将时间戳转换成日期_mysql 中查询时如何将时间戳转换为日期格式 / 日期格式转换为时间戳...
  20. 【C语言】一文看懂指针和内存

热门文章

  1. IT技术人员的六大方向
  2. mysql 军规_在互联网大厂必须遵守的MySql开发军规
  3. 蒲公英——APP内测分发平台
  4. 如何禁止计算机自动安装驱动,win10系统禁止自动安装驱动的详细技巧
  5. MySQL基础知识-MySQL概述安装,单表增删改查,函数,约束,多表查询,事物
  6. Ant Design mentions组件更改样式
  7. 展锐平台 Android 10.0 OTA升级开机Logo
  8. PS - 图层显示索引不能做修改(将索引图层改为正常图层)
  9. Modbus协议应用纪实
  10. 转:C语言面试题大汇总 (图像处理方向)