符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
package com.zhh.test;
创新互联公司专注于海门网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供海门营销型网站建设,海门网站制作、海门网页设计、海门网站官网定制、微信小程序开发服务,打造海门网络公司原创品牌,更为您提供海门网站排名全网营销落地服务。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JB extends JFrame implements ActionListener
{
private JTextField Input1,Input2,Input3;
private JButton btnOK;
private static final String OK="计算";
private JTextField ShowAnswer;
public JB(String strTitle)
{
super(strTitle);
Container c=getContentPane();
c.setLayout(new FlowLayout());
Input1=new JTextField(4);
Input2=new JTextField(4);
Input3=new JTextField(4);
ShowAnswer=new JTextField(4);
btnOK=new JButton(OK);
c.add(new JLabel("请输入待计算的两个数据:"));
c.add(Input1);
c.add(Input2);
c.add(new JLabel("请输入计算符(1 for + ,2 for - ,3 for * ,4 for / ):"));
c.add(Input3);
c.add(new JLabel("计算结果:"));
c.add(ShowAnswer);
c.add(btnOK);
btnOK.addActionListener(this);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.setSize(310,100);
this.setVisible(true);
}
public static void main(String[] args)
{
new JB("JButtonTest Testing!!!");
}
public void actionPerformed(ActionEvent e){
int num4 = 0;
int num1=Integer.parseInt(Input1.getText());
int num2=Integer.parseInt(Input2.getText());
int num3=Integer.parseInt(Input3.getText());
if(num3==1){ num4=num1+num2 ;}
if(num3==2){ num4=num1-num2 ;}
if(num3==3){ num4=num1*num2 ;}
if(num3==4){ num4=num1/num2 ;}
ShowAnswer.setText(String.valueOf(num4));
}
}
LOGIN.JSP
%@ page contentType="text/html;charset=gb2312"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%
// 判断是否有错误信息,如果有则打印
// 如果没有此段代码,则显示时会直接打印null
if(request.getAttribute("err")!=null)
{
%
h2%=request.getAttribute("err")%/h2
%
}
%
form action="login_conf.jsp" method="post"
table width="80%"
tr
td colspan="2"用户登陆/td
/tr
tr
td用户名:/td
tdinput type="text" name="id"/td
/tr
tr
td密 码:/td
tdinput type="password" name="password"/td
/tr
tr
td colspan="2"
input type="submit" value="登陆"
input type="reset" value="重置"
/td
/tr
/table
/form
/center
/body
/html
LOGIN_CONF.JSP
%@ page contentType="text/html;charset=gb2312"%
%@ page import="java.sql.*"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:three" ;
String DBUSER = "scott" ;
String DBPASSWORD = "tiger" ;
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
%
%
// 声明一个boolean变量,用于保存用户是否合法的状态
boolean flag = false ;
// 接收参数
String id = request.getParameter("id") ;
String password = request.getParameter("password") ;
%
%
String sql = "SELECT name FROM person WHERE id=? and password=?" ;
try
{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setString(1,id) ;
pstmt.setString(2,password) ;
rs = pstmt.executeQuery() ;
if(rs.next())
{
// 用户合法
flag = true ;
// 将用户名保存在session之中
session.setAttribute("uname",rs.getString(1)) ;
}
else
{
// 保存错误信息
request.setAttribute("err","错误的用户名及密码!!!") ;
}
rs.close() ;
pstmt.close() ;
conn.close() ;
}
catch(Exception e)
{}
%
%
// 跳转
if(flag)
{
// 用户合法
%
jsp:forward page="login_success.jsp"/
%
}
else
{
// 用户非法
%
jsp:forward page="login.jsp"/
%
}
%
/center
/body
/html
LOGIN_SUCCESS.JSP
%@ page contentType="text/html;charset=gb2312"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%
if(session.getAttribute("uname")!=null)
{
// 用户已登陆
%
h2登陆成功/h2
h2欢迎font color="red" size="12"
%=session.getAttribute("uname")%
/font光临MLDN留言程序/h2
h3a href="list_notes.jsp"进入留言管理页面/a/h3
%
}
else
{
// 用户未登陆,提示用户登陆,并跳转
response.setHeader("refresh","2;URL=login.jsp") ;
%
您还未登陆,请先登陆!!!br
两秒后自动跳转到登陆窗口!!!br
如果没有跳转,请按a href="login.jsp"这里/a!!!br
%
}
%
/center
/body
/html
INSERT.JSP
%@ page contentType="text/html;charset=gb2312"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%
if(session.getAttribute("uname")!=null)
{
// 用户已登陆
%
form action="insert_do.jsp" method="post"
table
tr
td colspan="2"添加新留言/td
/tr
tr
td标题:/td
tdinput type="text" name="title"/td
/tr
tr
td作者:/td
tdinput type="text" name="author"/td
/tr
tr
td内容:/td
tdtextarea name="content" cols="30" rows="6"/textarea/td
/tr
tr
td colspan="2"
input type="submit" value="添加"
input type="reset" value="重置"
/td
/tr
/table
/form
h3a href="list_notes.jsp"回到留言列表页/a/h3
%
}
else
{
// 用户未登陆,提示用户登陆,并跳转
response.setHeader("refresh","2;URL=login.jsp") ;
%
您还未登陆,请先登陆!!!br
两秒后自动跳转到登陆窗口!!!br
如果没有跳转,请按a href="login.jsp"这里/a!!!br
%
}
%
/center
/body
/html
INSERT_DO.JSP
%@ page contentType="text/html;charset=gb2312"%
%@ page import="java.sql.*"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%
// 进行乱码处理
request.setCharacterEncoding("GB2312") ;
%
%
if(session.getAttribute("uname")!=null)
{
// 用户已登陆
%
%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:three" ;
String DBUSER = "scott" ;
String DBPASSWORD = "tiger" ;
Connection conn = null ;
PreparedStatement pstmt = null ;
%
%
// 声明一个boolean变量
boolean flag = false ;
// 接收参数
String title = request.getParameter("title") ;
String author = request.getParameter("author") ;
String content = request.getParameter("content") ;
%
%
// 现在note表中的主键是sequence生成
String sql = "INSERT INTO note VALUES(note_sequ.nextVal,?,?,?)" ;
try
{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setString(1,title) ;
pstmt.setString(2,author) ;
pstmt.setString(3,content) ;
pstmt.executeUpdate() ;
pstmt.close() ;
conn.close() ;
// 如果插入成功,则肯定能执行到此段代码
flag = true ;
}
catch(Exception e)
{}
%
%
response.setHeader("refresh","2;URL=list_notes.jsp") ;
if(flag)
{
%
留言添加成功,两秒后跳转到留言列表页!!!br
如果没有跳转,请按a href="list_notes.jsp"这里/a!!!
%
}
else
{
%
留言添加失败,两秒后跳转到留言列表页!!!br
如果没有跳转,请按a href="list_notes.jsp"这里/a!!!
%
}
%
%
}
else
{
// 用户未登陆,提示用户登陆,并跳转
response.setHeader("refresh","2;URL=login.jsp") ;
%
您还未登陆,请先登陆!!!br
两秒后自动跳转到登陆窗口!!!br
如果没有跳转,请按a href="login.jsp"这里/a!!!br
%
}
%
/center
/body
/html
LIST_NOTES.JSP
%@ page contentType="text/html;charset=gb2312"%
%@ page import="java.sql.*"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%
// 编码转换
request.setCharacterEncoding("GB2312") ;
if(session.getAttribute("uname")!=null)
{
// 用户已登陆
%
%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:three" ;
String DBUSER = "scott" ;
String DBPASSWORD = "tiger" ;
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
%
%
// 如果有内容,则修改变量i,如果没有,则根据i的值进行无内容提示
int i = 0 ;
String sql = null;
String keyword = request.getParameter("keyword") ;
// out.println(keyword) ;
if(keyword==null)
{
// 没有任何查询条件
sql = "SELECT id,title,author,content FROM note" ;
}
else
{
// 有查询条件
sql = "SELECT id,title,author,content FROM note WHERE title like ? or author like ? or content like ?" ;
}
try
{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = conn.prepareStatement(sql) ;
// 如果存在查询内容,则需要设置查询条件
if(keyword!=null)
{
// 存在查询条件
pstmt.setString(1,"%"+keyword+"%") ;
pstmt.setString(2,"%"+keyword+"%") ;
pstmt.setString(3,"%"+keyword+"%") ;
}
rs = pstmt.executeQuery() ;
%
form action="list_notes.jsp" method="POST"
请输入查询内容:input type="text" name="keyword"
input type="submit" value="查询"
/form
h3a href="insert.jsp"添加新留言/a/h3
table width="80%" border="1"
tr
td留言ID/td
td标题/td
td作者/td
td内容/td
td删除/td
/tr
%
while(rs.next())
{
i++ ;
// 进行循环打印,打印出所有的内容,以表格形式
// 从数据库中取出内容
int id = rs.getInt(1) ;
String title = rs.getString(2) ;
String author = rs.getString(3) ;
String content = rs.getString(4) ;
if(keyword!=null)
{
// 需要将数据返红
title = title.replaceAll(keyword,"font color=\"red\""+keyword+"/font") ;
author = author.replaceAll(keyword,"font color=\"red\""+keyword+"/font") ;
content = content.replaceAll(keyword,"font color=\"red\""+keyword+"/font") ;
}
%
tr
td%=id%/td
tda href="update.jsp?id=%=id%"%=title%/a/td
td%=author%/td
td%=content%/td
tda href="delete_do.jsp?id=%=id%"删除/a/td
/tr
%
}
// 判断i的值是否改变,如果改变,则表示有内容,反之,无内容
if(i==0)
{
// 进行提示
%
tr
td colspan="5"没有任何内容!!!/td
/tr
%
}
%
/table
%
rs.close() ;
pstmt.close() ;
conn.close() ;
}
catch(Exception e)
{}
%
%
}
else
{
// 用户未登陆,提示用户登陆,并跳转
response.setHeader("refresh","2;URL=login.jsp") ;
%
您还未登陆,请先登陆!!!br
两秒后自动跳转到登陆窗口!!!br
如果没有跳转,请按a href="login.jsp"这里/a!!!br
%
}
%
/center
/body
/html
UPDATE.JSP
%@ page contentType="text/html;charset=gb2312"%
%@ page import="java.sql.*"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%
if(session.getAttribute("uname")!=null)
{
// 用户已登陆
%
%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:three" ;
String DBUSER = "scott" ;
String DBPASSWORD = "tiger" ;
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
%
%
// 接收参数
int id = 0 ;
try
{
id = Integer.parseInt(request.getParameter("id")) ;
}
catch(Exception e)
{}
%
%
// 如果有内容,则修改变量i,如果没有,则根据i的值进行无内容提示
int i = 0 ;
String sql = "SELECT id,title,author,content FROM note WHERE id=?" ;
try
{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = conn.prepareStatement(sql) ;
// 设置查询条件
pstmt.setInt(1,id) ;
rs = pstmt.executeQuery() ;
%
%
if(rs.next())
{
i++ ;
// 进行循环打印,打印出所有的内容,以表格形式
// 从数据库中取出内容
id = rs.getInt(1) ;
String title = rs.getString(2) ;
String author = rs.getString(3) ;
String content = rs.getString(4) ;
%
form action="update_do.jsp" method="post"
table
tr
td colspan="2"添加新留言/td
/tr
tr
td标题:/td
tdinput type="text" name="title" value="%=title%"/td
/tr
tr
td作者:/td
tdinput type="text" name="author" value="%=author%"/td
/tr
tr
td内容:/td
tdtextarea name="content" cols="30" rows="6"%=content%/textarea/td
/tr
tr
td colspan="2"
input type="hidden" name="id" value="%=id%"
input type="submit" value="更新"
input type="reset" value="重置"
/td
/tr
/table
/form
%
}
else
{
%
没有发现,要更新的内容!!br
请确认要更新的留言是否存在!!br
%
}
%
%
rs.close() ;
pstmt.close() ;
conn.close() ;
}
catch(Exception e)
{}
%
h3a href="list_notes.jsp"回到留言列表页/a/h3
%
}
else
{
// 用户未登陆,提示用户登陆,并跳转
response.setHeader("refresh","2;URL=login.jsp") ;
%
您还未登陆,请先登陆!!!br
两秒后自动跳转到登陆窗口!!!br
如果没有跳转,请按a href="login.jsp"这里/a!!!br
%
}
%
/center
/body
/html
UPDATE_DO.JSP
%@ page contentType="text/html;charset=gb2312"%
%@ page import="java.sql.*"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%
// 进行乱码处理
request.setCharacterEncoding("GB2312") ;
%
%
if(session.getAttribute("uname")!=null)
{
// 用户已登陆
%
%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:three" ;
String DBUSER = "scott" ;
String DBPASSWORD = "tiger" ;
Connection conn = null ;
PreparedStatement pstmt = null ;
%
%
// 声明一个boolean变量
boolean flag = false ;
// 接收参数
String title = request.getParameter("title") ;
String author = request.getParameter("author") ;
String content = request.getParameter("content") ;
int id = 0 ;
try
{
id = Integer.parseInt(request.getParameter("id")) ;
}
catch(Exception e)
{}
%
%
// 更新note表中的数据
String sql = "UPDATE note set title=?,author=?,content=? WHERE id=?" ;
try
{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setString(1,title) ;
pstmt.setString(2,author) ;
pstmt.setString(3,content) ;
pstmt.setInt(4,id);
pstmt.executeUpdate() ;
pstmt.close() ;
conn.close() ;
// 如果修改成功,则肯定能执行到此段代码
flag = true ;
}
catch(Exception e)
{}
%
%
response.setHeader("refresh","2;URL=list_notes.jsp") ;
if(flag)
{
%
留言修改成功,两秒后跳转到留言列表页!!!br
如果没有跳转,请按a href="list_notes.jsp"这里/a!!!
%
}
else
{
%
留言修改失败,两秒后跳转到留言列表页!!!br
如果没有跳转,请按a href="list_notes.jsp"这里/a!!!
%
}
%
%
}
else
{
// 用户未登陆,提示用户登陆,并跳转
response.setHeader("refresh","2;URL=login.jsp") ;
%
您还未登陆,请先登陆!!!br
两秒后自动跳转到登陆窗口!!!br
如果没有跳转,请按a href="login.jsp"这里/a!!!br
%
}
%
/center
/body
/html
DELETE_DO.JSP
%@ page contentType="text/html;charset=gb2312"%
%@ page import="java.sql.*"%
html
head
titleJSP+JDBC 留言管理程序――登陆/title
/head
body
center
h1留言管理范例 ―― JSP + JDBC实现/h1
hr
br
%
if(session.getAttribute("uname")!=null)
{
// 用户已登陆
%
%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:three" ;
String DBUSER = "scott" ;
String DBPASSWORD = "tiger" ;
Connection conn = null ;
PreparedStatement pstmt = null ;
%
%
// 接收参数
int id = 0 ;
try
{
id = Integer.parseInt(request.getParameter("id")) ;
}
catch(Exception e)
{}
%
%
String sql = "DELETE FROM note WHERE id=?" ;
boolean flag = false ;
try
{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = conn.prepareStatement(sql) ;
// 设置删除条件
pstmt.setInt(1,id) ;
pstmt.executeUpdate() ;
pstmt.close() ;
conn.close() ;
flag = true ;
}
catch(Exception e)
{}
%
%
response.setHeader("refresh","2;URL=list_notes.jsp") ;
if(flag)
{
%
留言删除成功,两秒后跳转到留言列表页!!!br
如果没有跳转,请按a href="list_notes.jsp"这里/a!!!
%
}
else
{
%
留言删除失败,两秒后跳转到留言列表页!!!br
如果没有跳转,请按a href="list_notes.jsp"这里/a!!!
%
}
%
%
}
else
{
// 用户未登陆,提示用户登陆,并跳转
response.setHeader("refresh","2;URL=login.jsp") ;
%
您还未登陆,请先登陆!!!br
两秒后自动跳转到登陆窗口!!!br
如果没有跳转,请按a href="login.jsp"这里/a!!!br
%
}
%
/center
/body
/html
-- 创建表
-- 用户表(登陆)、留言表
-- 删除表
DROP TABLE person ;
DROP TABLE note ;
-- 删除序列
DROP SEQUENCE note_sequ ;
-- 创建序列
CREATE SEQUENCE note_sequ ;
-- 创建person表
CREATE TABLE person
(
id varchar(20) not null primary key ,
name varchar(20) ,
password varchar(20)
) ;
-- 创建留言表
CREATE TABLE note
(
id int not null primary key , -- sequence
title varchar(20) not null ,
author varchar(20) not null ,
content varchar(50) not null
) ;
-- 插入测试数据
INSERT INTO person VALUES ('LXH','李兴华','zzzzzz') ;
INSERT INTO person VALUES ('MLDN','魔乐','mmmmmm') ;
-- 事务提交
commit ;
先说说回复吧:
假如:
留言表(id , text )两个字段
回复表( id , text parentId )用来存放留言表id 三个字段
目前有一条留言
1001,'这是一条留言';
那么给这条留言的回复就是
1003 , '这是一条回复', 1001(这就是该留言的ID) 这样就把留言和回复关联上了
回复后点保存时,将数据传入后台,数据库做insert操作就行了
删除一样的
如果删除回复,直接传入回复的ID 即可
如果删除留言,得先判断该留言有没有回复,如果有回复,则先删除回复,在删除留言(外键约束)
meta http-equiv="Content-Type" content="text/html;charset=gb2312"
%@ Language=VBScript %
!--#INCLUDE FILE="config.asp" --
!--#INCLUDE FILE="guest_lib.asp" --%
dim ASPBook
dim StrSQL
if not isempty(request("page")) then
Mypage=cint(Request("page"))
else
Mypage=1
end if
set ASPBook = Server.CreateObject("ADODB.Recordset")
StrSQL = "Select * from guest order by ID desc"
ASPBook.open StrSQL,conn,1,1
ASPBook.pagesize=Mypagesize
maxpages=cint(ASPBook.pagecount)
totalsize=cint(Mypagesize)
ASPBook.absolutepage=Mypage
GuestTotal=ASPBook.RecordCount
if cint(Mypage) 1 then
if cint(Mypage) maxpages then
MESSAGE("li没有你所想去的页数!/li")
Response.End
end if
end if
HEADER "显示留言"
MyMenu
%
html
head
title[ 客户留言系统 ]/title
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
link rel="stylesheet" href="css/colorbird.css"
style
BODY {SCROLLBAR-FACE-COLOR: #D4D0C8; SCROLLBAR-HIGHLIGHT-COLOR: #999999; SCROLLBAR-SHADOW-COLOR: #999999; SCROLLBAR-3DLIGHT-COLOR: #FFFFFF; SCROLLBAR-ARROW-COLOR: #000000; SCROLLBAR-TRACK-COLOR: #E3E3E3; SCROLLBAR-DARKSHADOW-COLOR: #666666; }
/style
/head
body bgcolor="#FFFFFF" topmargin="0" leftmargin="0"
p align="center"a href="gb_sign.asp"
img border="0" src="IMAGES/sign.gif" alt="签写留言"/a/p
tdp align="center"font color="#000000"bfont face="Arial" size="1"Total of
font color="#ff0000"%=GuestTotal%/font messages, /font/b/font
font face="Arial"font size="1" color="#ff0000"%=MyPageSize%/fontfont size="1"
messages per page, You are on page/font/font/fontfont color="#FF0000"font size="1" face="Arial"%=cint(Mypage)%/font
%=Greeting%... font color="#000000"%PageLink%/font/p
/font
div align="right"/div/td
div align="center"
center
table width="590" border="0" cellspacing="0" cellpadding="0"
tr
td height="50"a href="gb_sign.asp"img src="IMAGES/shop.gif" alt="签写留言" width="89" height="25" border="0"/a/td
/tr
/table
table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#6699CC" width="590" height="197"
tr
td align="center" height="197"
table width="590" border="0" cellspacing="0" cellpadding="4" style="border-collapse: collapse" height="35" bgcolor="#F7F7F7"
tr
/tr
tr
/tr
/table
table cellspacing="1" border="1" width="592" height="23" style="border-collapse: collapse" cellpadding="0" bgcolor="#C6C3C6" bordercolorlight="#FFFFFF" bordercolordark="#000000" background="table.gif"
tr
td align="right" width="130" height="23"
p align="left"b
font color="#FFFFFF"留言者 :/font/b/p
/td
td align="right" width="445" height="23"
p align="left"b
font color="#FFFFFF"留言内容 :/font/b/p
/td
/tr
/table
table width="590" border="0" cellspacing="0" cellpadding="0"
%
If ASPBook.Eof or ASPBook.Bof then
Response.Write "TR"
Response.Write "TD bgcolor=" Color1 " align=center colspan=6FONT STYLE=font-size:9pt对不起,目前还没有任何留言,如要留言,请按“我要留言”图片!/FONT/TD"
else
i = 0
total = 0
do until ASPBook.Eof or total = totalsize
if i = 0 then
CColor = Color1
else
CColor = Color2
end if
%
tr bgcolor="%=CColor%"
td
table width="590" border="1" cellspacing="8" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111"
tr
/tr
/table
table width="590" border="0" cellpadding="2" style="border-collapse: collapse" bordercolor="#111111" height="1"
tr
td width="137" rowspan="3" height="1" valign="top"
table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="99%" id="AutoNumber2" height="96"
tr
td width="100%" align="center" height="12"b%=ASPBook("名字")%/b/td
/tr
tr
td width="100%" align="center" height="54"%if ASPBook("性别") = "boy" then%
br
img src="images/boy.gif" alt="英俊潇洒的 %=ASPBook("名字")% 先生" align="middle" border="0"
%elseif ASPBook("性别") = "girl" then%
img src="images/girl.gif" alt="美丽又温柔的 %=ASPBook("名字")% 小姐" align="middle" border="0"
br
%end if%/td
/tr
tr
td width="100%" align="center" height="28"Form: %=ASPBook("来自")% /td
/tr
/table
/td
td width="234" height="1"font size="1"
font color="#000000" class="littel"
img src="./icons/em%=ASPBook("表情")%.gif" border="0" align="ABSCENTER"/fontfont color="#0000FF" class="littel"On:
%=ASPBook("留言日期")%/font/fontfont size="1" color="#0000FF"
/font/td
td width="212" height="1"%if ASPBook("邮件")"" then%
a href="mailto:%=ASPBook("邮件")%"
img src="images/email.gif" ALIGN="absmiddle" border="0" width="15" height="16"/a
%end if% %if ASPBook("主页")"" and ASPBook("主页")"http://" then%
a href="%=ASPBook("主页")%" Target="_blank"
img src="images/home.gif" ALIGN="absmiddle" border="0"/a
%end if% %if ASPBook("ICQ")"" then%
img src="images/icq.gif" alt="ICQ:%=ASPBook("ICQ")%" align="absmiddle" border="0" width="15" height="16"
%if ASPBook("OICQ")"" then% %end if%
a href=";%=ASPBook("OICQ")%" target="_blank"
img src="images/oicq.gif" alt="OICQ:%=ASPBook("OICQ")%" align="absmiddle" border="0" width="16" height="16"/a
%end if%
img src="images/ip.gif" alt="%=ASPBook("IP")%" align="absmiddle" border="0" width="13" height="16"
img src="images/system.gif" alt="%=ASPBook("系统")%" align="absmiddle" border="0" width="15" height="16"/td
/tr
tr
td width="450" height="14" colspan="2" valign="top"%=ASPBook("留言")% /td
/tr
tr
%if ASPBook("Reply")"" then%td width="450" height="17" colspan="2" valign="top"
font color="#FF0000"Reply :b /b/font
font color="#0000FF" class="littel" size="1"(%=ASPBook("Reply_Date")%)/fontbr
img src="./icons/em%=ASPBook("Reply_Icon")%.gif" border="0" align="ABSCENTER"%=ASPBook("Reply")%/font/td
%end if%/tr
/table
table width="590" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111"
tr
td width="137" rowspan="2" /td
td width="450"/td
/tr
tr
td width="450" /td
/tr
/table
table width="590" height="24" border="0" cellpadding="0" cellspacing="1" bordercolor="#DCE8F3" bordercolorlight="#FFFFFF" bgcolor="#DCE8F3" style="border-collapse: collapse"
tr
td align="right" width="131" height="20"
p align="left" /p
/td
td align="right" width="448" height="20"
a href="gb_reply.asp?page=%=mypage%Number=%=ASPBook("ID")%"
img src="images/quote.gif" alt="回复该留言" align="absmiddle" border="0" width="16" height="16"/a
a href="gb_delete.asp?page=%=mypage%Number=%=ASPBook("ID")%"
img src="images/recycle.gif" alt="删除该留言" align="absmiddle" border="0" width="16" height="16"/a/td
/tr
/table
/td
/tr
%
ASPBook.MoveNext
i = i + 1
if i = 2 then i = 0
total = total + 1
loop
% %END IF%
/table
%COPYRIGHT%
table border="0" cellpadding="2" cellspacing="0" width="590" height="1" bgcolor="#F7F7F7" style="border-collapse: collapse" bordercolor="#FFFFFF" bordercolorlight="#FFFFFF"
tr
td width="131" height="1"
p align="center"/p
/td
td align="right" width="448" height="1"font color="#000000"%PageLink%
/font /td
/tr
/table
/td
/tr
/table
/center
/div
div align="center"
center
table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="592" id="AutoNumber1"
tr
td width="100%"
p align="center"a href="gb_sign.asp" /abr
/p
/td
/tr
/table
/center
/div
/body
/html
%
function PageLink
PageShowSize = 10
Scriptname=Request.Servervariables("script_name")
PageNextSize=int((MyPage-1)/PageShowSize)+1
Pagetpage=int((GuestTotal-1)/MyPageSize)+1
if Maxpages 1 then
if PageNextSize 1 then
PagePrev=PageShowSize*(PageNextSize-1)
Response.write "a href='" Scriptname "?page=" PagePrev "'[]/a-"
end if
if Mypage-1 0 then
Prev_Page = MyPage - 1
Response.write "a href='" Scriptname "?page=" Prev_Page "'[]/a "
end if
if maxpages=PageNextSize*PageShowSize then
PageSizeShow = PageShowSize
else
PageSizeShow = Maxpages-PageShowSize*(PageNextSize-1)
end if
for PageCounterSize=1 to PageSizeShow
PageLink = (PageCounterSize+PageNextSize*10)-10
if PageLink cint(Mypage) then
Response.write "a href='" Scriptname "?page=" PageLink "'[" PageLink "]/a "
else
Response.Write PageLink " "
end if
next
if Mypage+1 =Pagetpage then
Next_Page = MyPage + 1
Response.write "a href='" Scriptname "?page=" Next_Page "'[]/a"
end if
if maxpages PageShowSize*PageNextSize then
PageNext = PageShowSize * PageNextSize + 1
Response.write "-a href='" Scriptname "?page=" PageNext "'[]/a"
end if
else
Response.write "[1]"
end if
END function
set ASPBook=nothing
conn.Close
set conn = nothing
%
绝对开源,绝对明了的留言板,便于学习的源码
用JAVA写的留言板原代码
/*
* guestbookServlet.java
*
* */
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.Date;
/**
*
* */
public class guestbookServlet extends HttpServlet {
boolean debug=false;
String sDBDriver;
Connection conn=null;
ResultSet rs=null;
/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
if(debug)
sDBDriver=new String("sun.jdbc.odbc.JdbcOdbcDriver");
else
sDBDriver=new String("org.gjt.mm.mysql.Driver");
try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("Driver类初始化:"+e.getMessage());
}
}
/** Destroys the servlet.
*/
public void destroy() {
}
/** Processes requests for both HTTP codeGET/code and codePOST/code methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html;charset=gb2312");
java.io.PrintWriter out = response.getWriter();
boolean empty=true;
boolean noResult=true;
String sqlStr;
int currentPage=0;
int totalPage=0;
int reccount=0;
ResultSet myrs=null;
String username=request.getParameter("username");
String email=request.getParameter("email");
String ucontent=request.getParameter("ucontent");
String ipage=request.getParameter("ipage");
if(ipage==null||ipage.length()==0)
currentPage=1;
else
currentPage=Integer.parseInt(ipage);
if((username==null||username.length()==0)||(ucontent==null||ucontent.length()==0))empty=true;
else empty=false;
Date myDate=new Date();
//String intime=new String(String.valueOf(myDate.getYear()+1990)+String.valueOf(myDate.getMonth()));
String year=String.valueOf(myDate.getYear()+1900);
String month=String.valueOf(myDate.getMonth()+1);
if(month.length()==1)
month=new String("0"+month);
String days=String.valueOf(myDate.getDate());
if(days.length()==1)
days=new String("0"+days);
String hours=String.valueOf(myDate.getHours());
if(hours.length()==1)
hours=new String("0"+hours);
String minutes=String.valueOf(myDate.getMinutes());
if(minutes.length()==1)
minutes=new String("0"+minutes);
String intime=year+"-"+month+"-"+days+" "+hours+":"+minutes;
if(email==null||email.length()==0)
email=new String("");
if(!empty){
//username=convert(username);
//email=convert(email);
//ucontent=convert(ucontent);
sqlStr="insert into Mintegbook(Mname,Memail,Mcontent,Mtime,Mid) values("+username+","+email+","+ucontent+","+intime+",1)";
getDsnConn();
executeInsert(sqlStr);
}
sqlStr=new String("select Mname,Memail,Mcontent,Mtime from Mintegbook order by Mtime DESC");
getDsnConn();
reccount=getRecordCount("Mintegbook");
if(reccount==0)
noResult=true;
else
noResult=false;
if(!noResult){
int ipageSize=10;
totalPage=getTotalPage("Mintegbook",ipageSize);
if(currentPagetotalPage)
currentPage=totalPage;
int cursor=(currentPage-1)*ipageSize+1;
try{
myrs=executeScrollableQuery(sqlStr);
myrs.absolute(cursor);
}
catch(SQLException e){
noResult=true;
}
}
out.println("HTMLHEADTITLE我的Servlet留言板/TITLE");
out.println("META http-equiv="Content-Type" content="text/html; charset=gb2312"");
out.println("STYLE type="text/css"");
out.println("!--");
out.println(".mytext { font-family: "宋体"; font-size: 12px}");
out.println(" --");
out.println("/STYLE");
out.println("/HEAD");
out.println("BODY bgcolor="#FFFFFF" text="#000000"");
out.println("TABLE width="600" border="0" cellspacing="0" cellpadding="0" align="CENTER" class="mytext"");
out.println("TRTD height="22" | a href=""我的主页/a | 我的Servlet留言板(A href="mailto:yf188@21cn.com"川石/A制作)/TD/TR");
out.println("TRTD height="1" bgcolor="#999933"/TD/TR");
out.println("/TABLE");
out.println("BR");
out.println("TABLE width="600" border="0" cellspacing="0" cellpadding="0" align="CENTER" class="mytext"");
out.println("TRTD height="8"/TD/TR");
out.println("TRTD height="18" bgcolor="#f7f7f7"DIV align="right"");
out.println("共有 "+reccount + " 条留言 ");
out.println(" 当前第font color=#ff0000"+currentPage+"/font/共 "+totalPage+" 页 ");
if(currentPage1)
out.println(" a href=guestbookServlet?ipage=1首页/a a href=guestbookServlet?ipage="+(currentPage-1)+"上一页/a ");
else
out.println(" 首页 上一页 ");
if(currentPagetotalPage)
out.println(" a href=guestbookServlet?ipage="+(currentPage+1)+"下一页/a a href=guestbookServlet?ipage="+totalPage+"末页/a ");
else
out.println(" 下一页 末页 ");
out.println("/DIV/TD/TR");
out.println("/TABLE");
out.println("BR");
//这里是显示留言内容
if(!noResult){
String dname;
String demail;
String dcontent;
String dtime;
Date temptime;
try{
do{
dname=new String(myrs.getString("Mname"));
demail=new String(myrs.getString("Memail"));
dcontent=new String(myrs.getString("Mcontent"));
try{
dtime=new String(myrs.getObject("Mtime").toString());
}
catch(java.lang.NullPointerException e){
dtime=new String("2001-04-06 12:30");
}
if(dname==null)
dname=new String("川石");
if(demail==null)
demail=new String("yf188@21cn.com");
if(dcontent==null)
dcontent=new String("test");
if(dtime==null)
dtime=new String("2001-04-06 12:30");
dname=convert(dname);
dcontent=convert(dcontent);
//temptime=myrs.getDate("Mtime");
/*
String tempyear=String.valueOf(temptime.getYear()+1900);
String tempmonth=String.valueOf(temptime.getMonth()+1);
if(tempmonth.length()==1)
tempmonth=new String("0"+tempmonth);
String tempdays=String.valueOf(temptime.getDate());
if(tempdays.length()==1)
tempdays=new String("0"+tempdays);
String tempminute=String.valueOf(temptime.getMinutes());
if(tempminute.length()==1)
tempminute=new String("0"+tempminute);
String temphours=String.valueOf(temptime.getHours());
if(temphours.length()==1)
temphours=new String("0"+temphours);
String dtime=tempyear+" 年 "+ tempmonth +" 月 "+ tempdays +" 日 " + temphours+ " 时 "+ tempminute + " 分 ";
*/
out.println("TABLE width="600" border="0" cellspacing="0" cellpadding="4" align="CENTER" class="mytext"");
out.println("TRTD姓名 A href="mailto:"+demail+"""+dname+"/A 留言时间:"+dtime+"/TD/TR");
out.println("TRTD height="10"/TD/TR");
out.println("TRTD height="10""+dcontent+"/TD/TR");
out.println("/TABLE");
out.println("HR width="600" size="1"");
}while(myrs.next());}
catch(SQLException e){
out.println("error found");
}
}
else{
out.println("还没有留言!");
}
//结束
out.println("FORM name="form1" method="post" action="guestbookServlet"");
out.println("TABLE width="600" border="0" cellspacing="0" cellpadding="4" align="CENTER" class="mytext"");
out.println("TRTD width="80"姓名:/TDTDINPUT type="text" name="username"*/TD/TR");
out.println("TRTDEmail:/TDTDINPUT type="text" name="email"*/TD/TR");
out.println("TRTD留言:/TDTDTEXTAREA name="ucontent" cols="65" rows="4"/TEXTAREA/TD/TR");
out.println("/TABLE");
out.println("TABLE width="400" border="0" cellspacing="0" cellpadding="6" align="CENTER" class="mytext"");
out.println("TRTD height="15" width="200" /TDTD /TD/TR");
out.println("TRTDDIV align="RIGHT"INPUT type="button" name="Button" value=" 提 交 " style="cursor:hand" onclick="javascript:check()"/DIV/TD");
out.println("TDINPUT type="reset" name="Submit2" value=" 重 置 "/TD/TR");
out.println("/TABLE");
out.println("/FORM");
out.println("TABLE width="400" border="0" cellspacing="0" cellpadding="4" align="CENTER" class="mytext"");
out.println("TRTD width="15" /TD/TR");
out.println("TRTDDIV align="LEFT"/DIV/TD/TR");
out.println("TRTD /TD/TR");
out.println("/TABLE");
out.println("/BODY");
out.println("/HTML");
out.println("SCRIPT language="javascript"");
out.println("function check(){");
out.println("if(form1.username.value.length1||form1.ucontent.value.length1)");
out.println("{alert(姓名和留言是必须有的!);}else{form1.submit();}}");
out.println("/SCRIPT");
out.close();
}
/** Handles the HTTP codeGET/code method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
/** Handles the HTTP codePOST/code method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
protected void getDsnConn(){
String sqlUrl="jdbc:mysql://10.0.0.1/你申请用户名?user=你的名字password=你的帐号";
try{
if(debug)
conn=DriverManager.getConnection("jdbc:odbc:ODBC源","用户名","密码口令");
else
conn=DriverManager.getConnection(sqlUrl);
}
catch(SQLException es){
System.err.println("和库连接时出错:"+es.getMessage());
}
}
protected void executeInsert(String sqlStr){
try{
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
}
catch(SQLException es){
System.err.println("执行插入时:"+es.getMessage());
}
}
protected void executeUpdate(String sqlStr){
try{
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
}
catch(SQLException e){
System.err.println("error in query record");
}
}
//查寻
protected ResultSet executeQuery(String sqlStr){
rs=null;
try{
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
}
catch(SQLException ex){
System.err.println("执行查寻出错:"+ex.getMessage());
}
return rs;
}
protected ResultSet executeScrollableQuery(String sqlStr){
rs=null;
try{
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sqlStr);
}
catch(SQLException e){
System.err.println("执行动态查寻出错");
}
return rs;
}
//得到表记录总数
protected int getRecordCount(String sTableName){
rs=null;
int CountResult=0;
String sqlStr="select count(*) from "+sTableName;
try{
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
if(rs.next())
CountResult=rs.getInt(1);
rs=null;
stmt.close();
}
catch(SQLException ex){
System.err.println(ex.getMessage());
}
return CountResult;
}
//得到记录总页数
protected int getTotalPage(String sTableName,int iPageSize){
int totalPage;
int totalRecNum=getRecordCount(sTableName);
if(totalRecNum%iPageSize==0)
totalPage=totalRecNum/iPageSize;
else
totalPage=totalRecNum/iPageSize+1;
return totalPage;
}
protected String convert(String InputStr){
String converted=new String();
byte[] bytes;
try{
bytes=InputStr.getBytes("ISO8859-1");
converted=new String(bytes,"GB2312");
}
catch(java.io.UnsupportedEncodingException e){
System.out.print("error");
}
return converted;
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
}
您好。我重新地帮你写了代码,完全地符合了你的图片中的界面要求、功能要求。代码如下:(解决了问题,记得给我分哦~^_^呵呵……)
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
public class Liuyb extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JTextArea jTextArea = null;
private JScrollPane jScrollPane = null;
private JLabel jLabel1 = null;
private JComboBox jComboBox = null;
private JLabel jLabel2 = null;
private JTextField jTextField = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JButton jButton3 = null;
/**
* This is the default constructor
*/
public Liuyb() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setContentPane(getJContentPane());
this.setTitle("留言板程序");
this.setBounds(new Rectangle(0, 0, 640, 480));
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(214, 407, 45, 24));
jLabel2.setFont(new Font("Dialog", Font.BOLD, 14));
jLabel2.setText("地说:");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(32, 407, 15, 24));
jLabel1.setFont(new Font("Dialog", Font.BOLD, 14));
jLabel1.setText("你");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(283, 15, 45, 20));
jLabel.setHorizontalAlignment(SwingConstants.CENTER);
jLabel.setFont(new Font("Dialog", Font.BOLD, 14));
jLabel.setText("留言板");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel, null);
jContentPane.add(getJScrollPane(), null);
jContentPane.add(jLabel1, null);
jContentPane.add(getJComboBox(), null);
jContentPane.add(jLabel2, null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(getJButton2(), null);
jContentPane.add(getJButton3(), null);
}
return jContentPane;
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setText("留言内容:");
jTextArea.setEditable(false);
}
return jTextArea;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(22, 49, 534, 347));
jScrollPane.setViewportView(getJTextArea());
}
return jScrollPane;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
jComboBox = new JComboBox();
jComboBox.setBounds(new Rectangle(54, 407, 149, 24));
String[] mycbox={"微笑","大笑","痛苦"};
jComboBox.addItem(mycbox[0]);
jComboBox.addItem(mycbox[1]);
jComboBox.addItem(mycbox[2]);
}
return jComboBox;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(265, 407, 231, 24));
}
return jTextField;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(505, 407, 70, 24));
jButton.setText("提交");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jTextArea.setText(jTextArea.getText()+"\r\n"+"你"+jComboBox.getSelectedItem().toString()+"地说:"+jTextField.getText());
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(565, 51, 60, 32));
jButton1.setText("清屏");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jTextArea.setText("留言内容:");
}
});
}
return jButton1;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(new Rectangle(565, 112, 60, 32));
jButton2.setText("置顶");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jTextArea.setCaretPosition(0);
}
});
}
return jButton2;
}
/**
* This method initializes jButton3
*
* @return javax.swing.JButton
*/
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setBounds(new Rectangle(565, 173, 60, 32));
jButton3.setText("至尾");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jTextArea.setCaretPosition((int)jTextArea.getText().length());
}
});
}
return jButton3;
}
public static void main(String args[]){
new Liuyb();
}
}