如何使用JSP+MySQL创建留言本(三)
2007-08-05 00:42
701 查看
下面我们开始建立留言的页面!
<%@page
import ="java.util.*"
import ="java.text.*"
import="java.sql.*"
import ="java.io.*"
import ="java.lang.*"
contentType="text/html; charset=gb2312"
%>
<%
class CommentError// throws java.lang.NullPointerException
{ public String Username="",Sex="",Address="",Postal="",Oicq="",Icq="",Tel="",Comment="";
public boolean NoError=true;//false;
public int ErrorCount=0;
private boolean IsNumber(String s1) {}
public String font (String se) {}
public String Comment_Er(String se) {}
public void Username (String se) {}
public void Sex (String se) {}
public void Address (String se) {}
public void Comment (String se) {}
public void Tel (String se) {}
public void Postal (String se) {}
public void Oicq (String se) {}
public void Icq (String se) {}
}
class FormatComment
{ public String Replace(String source, String oldString, String newString) {}
public String formatint(String se) {}
public String fromatcomment(String se) {}
public String toHtmlInput(String str) {}
public String toHtml(String str) {}
public String toSql(String str) {}//转换为可以加入Myqal的格式
}
%>
FrontPage 4.0">
萍慧jsp留言薄
JAVA天堂
<%! String username,sex,address,post,oicq,icq,telnumber,comment,email,url.urltitle;
%>
<%
try{ username=request.getParameter("name");
}catch (NullPointerException e){ username="";}
try{ comment=request.getParameter("comment");
}catch (NullPointerException e){ comment="";}
try{ sex=request.getParameter("sex");
}catch (NullPointerException e){ sex="";}
try{ address=request.getParameter("address");
}catch (NullPointerException e){ address="";}
try{ post=request.getParameter("postal");
}catch (NullPointerException e){ post="";}
try{ oicq=request.getParameter("oicq");
}catch (NullPointerException e){ oicq="";}
try{ icq=request.getParameter("icq");
}catch (NullPointerException e){ icq="";}
try{ telnumber=request.getParameter("telphone");
}catch (NullPointerException e) { telnumber= ""; }
try{ email=request.getParameter("email");
}catch (NullPointerException e) { email= ""; }
try{ url=request.getParameter("url");
}catch (NullPointerException e) { url= ""; }
try{ urltitle=request.getParameter("urltitle");
}catch (NullPointerException e) { urltitle= ""; }
String ip=request.getRemoteAddr();//得到IP地址
String time=(new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss", Locale.US )).format(new java.util.Date());
String userid="";
String MyQuery="";
此处我调用了一个对留言进行合法检验的类
JAVA天堂
CommentError testcomment= new CommentError();
testcomment.Username(username);
testcomment.Postal (post);
testcomment.Sex(sex);
testcomment.Address(address);
testcomment.Tel(telnumber);
testcomment.Comment(comment);
testcomment.Oicq(oicq);
testcomment.Icq(icq);
if (testcomment.NoError) //留言中没有错误,写数据库
try {//写数据库成功
java.sql.Connection sqlConn; //数据库连接对象
java.sql.Statement sqlStmt; //语句对象
java.sql.ResultSet sqlRst; //结果集对象
//登记JDBC驱动对象
Class.forName ("org.gjt.mm.mysql.Driver").newInstance ();
//连接数据库
sqlConn= java.sql.DriverManager.getConnection ("jdbc:mysql://localhost/pinghui","test","");
//创建语句对象
sqlStmt=sqlConn.createStatement (java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
//执行Sql语句
此处调用了一个对留言进行处理的类,是留言能被Mysql承认,
FormatComment FC= new FormatComment();
oicq=FC.formatint(oicq);
icq=FC.formatint(icq); JAVA天堂
post=FC.formatint(post);
telnumber=FC.formatint(telnumber);
username=FC.toSql(username);
comment=FC.toSql(comment);
MyQuery="insert into comment (username,sex,address,ip,post,oicq,icq,telnumber,comment,time,url,email) values (""+username+"",""+sex+"",""+address+"",""+ip+"","+post+","+oicq+","+icq+",""+telnumber+"",""+comment+"",now(),""+url+"",""+email+"");";
sqlRst=sqlStmt.executeQuery (MyQuery); //向数据库中加入数据
sqlRst.close();//关闭结果集对象
sqlStmt.close ();//关闭语句对象
sqlConn.close(); //关闭数据库连接
out.print (time);
%>
留言成功,谢谢!
ICQ:<%=icq%>
Email:
网址:
留言:<%=comment%>
-<%=time %>(来自<%=ip %>)
<%
} catch (SQLException e) //写数据库失败
{ out.print ("留言失败");
out.print (MyQuery);
out.print (userid);
}
else
{
out.print ("总共有"+testcomment.ErrorCount+"条错误数据,请修改!");
%>
javascript">
<%=testcomment.Comment_Er("comment")%>请注意:你所输入的内容中,昵称和留言为必须输入的项目!
不支持html标志
<%
}
%>
[b]来自:http://www.javah.net/JSP_JSF/20070514/1219.html[/b]
<%@page
import ="java.util.*"
import ="java.text.*"
import="java.sql.*"
import ="java.io.*"
import ="java.lang.*"
contentType="text/html; charset=gb2312"
%>
<%
class CommentError// throws java.lang.NullPointerException
{ public String Username="",Sex="",Address="",Postal="",Oicq="",Icq="",Tel="",Comment="";
public boolean NoError=true;//false;
public int ErrorCount=0;
private boolean IsNumber(String s1) {}
public String font (String se) {}
public String Comment_Er(String se) {}
public void Username (String se) {}
public void Sex (String se) {}
public void Address (String se) {}
public void Comment (String se) {}
public void Tel (String se) {}
public void Postal (String se) {}
public void Oicq (String se) {}
public void Icq (String se) {}
}
class FormatComment
{ public String Replace(String source, String oldString, String newString) {}
public String formatint(String se) {}
public String fromatcomment(String se) {}
public String toHtmlInput(String str) {}
public String toHtml(String str) {}
public String toSql(String str) {}//转换为可以加入Myqal的格式
}
%>
FrontPage 4.0">
萍慧jsp留言薄
JAVA天堂
<%! String username,sex,address,post,oicq,icq,telnumber,comment,email,url.urltitle;
%>
<%
try{ username=request.getParameter("name");
}catch (NullPointerException e){ username="";}
try{ comment=request.getParameter("comment");
}catch (NullPointerException e){ comment="";}
try{ sex=request.getParameter("sex");
}catch (NullPointerException e){ sex="";}
try{ address=request.getParameter("address");
}catch (NullPointerException e){ address="";}
try{ post=request.getParameter("postal");
}catch (NullPointerException e){ post="";}
try{ oicq=request.getParameter("oicq");
}catch (NullPointerException e){ oicq="";}
try{ icq=request.getParameter("icq");
}catch (NullPointerException e){ icq="";}
try{ telnumber=request.getParameter("telphone");
}catch (NullPointerException e) { telnumber= ""; }
try{ email=request.getParameter("email");
}catch (NullPointerException e) { email= ""; }
try{ url=request.getParameter("url");
}catch (NullPointerException e) { url= ""; }
try{ urltitle=request.getParameter("urltitle");
}catch (NullPointerException e) { urltitle= ""; }
String ip=request.getRemoteAddr();//得到IP地址
String time=(new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss", Locale.US )).format(new java.util.Date());
String userid="";
String MyQuery="";
此处我调用了一个对留言进行合法检验的类
JAVA天堂
CommentError testcomment= new CommentError();
testcomment.Username(username);
testcomment.Postal (post);
testcomment.Sex(sex);
testcomment.Address(address);
testcomment.Tel(telnumber);
testcomment.Comment(comment);
testcomment.Oicq(oicq);
testcomment.Icq(icq);
if (testcomment.NoError) //留言中没有错误,写数据库
try {//写数据库成功
java.sql.Connection sqlConn; //数据库连接对象
java.sql.Statement sqlStmt; //语句对象
java.sql.ResultSet sqlRst; //结果集对象
//登记JDBC驱动对象
Class.forName ("org.gjt.mm.mysql.Driver").newInstance ();
//连接数据库
sqlConn= java.sql.DriverManager.getConnection ("jdbc:mysql://localhost/pinghui","test","");
//创建语句对象
sqlStmt=sqlConn.createStatement (java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
//执行Sql语句
此处调用了一个对留言进行处理的类,是留言能被Mysql承认,
FormatComment FC= new FormatComment();
oicq=FC.formatint(oicq);
icq=FC.formatint(icq); JAVA天堂
post=FC.formatint(post);
telnumber=FC.formatint(telnumber);
username=FC.toSql(username);
comment=FC.toSql(comment);
MyQuery="insert into comment (username,sex,address,ip,post,oicq,icq,telnumber,comment,time,url,email) values (""+username+"",""+sex+"",""+address+"",""+ip+"","+post+","+oicq+","+icq+",""+telnumber+"",""+comment+"",now(),""+url+"",""+email+"");";
sqlRst=sqlStmt.executeQuery (MyQuery); //向数据库中加入数据
sqlRst.close();//关闭结果集对象
sqlStmt.close ();//关闭语句对象
sqlConn.close(); //关闭数据库连接
out.print (time);
%>
留言成功,谢谢!
昵称:<%=username%> | 性别:<%=sex%> | 地址:<%=address %> |
电话:<%=telnumber%> | 邮编:<%=post%> | OICQ:<%=oicq%> |
Email:
网址:
留言:<%=comment%>
-<%=time %>(来自<%=ip %>)
<%
} catch (SQLException e) //写数据库失败
{ out.print ("留言失败");
out.print (MyQuery);
out.print (userid);
}
else
{
out.print ("总共有"+testcomment.ErrorCount+"条错误数据,请修改!");
%>
javascript">
| Email:<%//=testcomment.Comment_Er("")%> | ||||||
网 址:<%//=testcomment.Comment_Er("")%> | |||||||
<%if (comment!=null)out.print (comment);%> | |||||||
不支持html标志
<%
}
%>
[b]来自:http://www.javah.net/JSP_JSF/20070514/1219.html[/b]
相关文章推荐
- 如何使用JSP+MySQL创建留言本(二)
- 如何使用JSP+MySQL创建留言本(一)
- 如何使用JSP+MySQL创建留言本(一)
- 如何使用JSP+MySQL创建留言本(三)
- 如何使用JSP+MySQL创建留言本(三)
- 如何使用JSP+MySQL创建留言本(二)
- 如何使用JSP+MySQL创建留言本(二)
- 如何使用JSP+MySQL创建留言本(一)
- 如何使用JSP+MySQL创建留言本(二)
- 如何使用JSP+MySQL创建留言本(三)
- 如何使用jsp+mysql创建留言本
- 如何使用JSP+MySQL创建留言本
- 如何使用JSP+MySQL创建留言本
- 在myeclipse中创建JSP时,如何使用自定义的JSP模板
- MySQL中日期类型数据的使用:如何让字段保存记录的创建时间和最后修改时间
- 在 MySQL Workbench 中如何可视的建立 MySQL 物理数据模型,并使用它来创建一个 MySQL 数据库
- 关于如何使用Navicat(11.1.13) for MySQL如何创建存储过程
- Web服务器是如何使用JSP来创建网页
- 如何在Jsp中使用JDBC来联结MySql
- MySQL中视图的定义、原理和如何使用、创建