<%! 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-Adresse anzeigen
String time=(new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss", Locale.US )).format(new java.util.Date());
String userid="";
String MyQuery="";
此处我调用了一个对留言进行合法检验的类
CommentError testcomment= new CommentError();
testcomment.Benutzername(Benutzername);
testcomment.Postal (Beitrag);
testcomment.Sex(sex);
testcomment.Address(address);
testcomment.Tel(telnumber);
testcomment.Comment(comment);
testcomment.Oicq(oicq);
testcomment.Icq(icq);
if (testcomment.NoError) // 留言中没有错误,写数据库
Versuchen Sie es mit {//写数据库成功
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);
post=FC.formatint(post);
telnumber=FC.formatint(telnumber);
Benutzername=FC.toSql(Benutzername);
comment=FC.toSql(comment);
MyQuery="In Kommentar einfügen (Benutzername, Geschlecht, Adresse, IP, Beitrag, OICQ, ICQ, Telefonnummer, Kommentar, Uhrzeit, URL, E-Mail) Werte ('"+Benutzername+','"+Geschlecht+"','"+ Adresse+"','"+ip+"',+post+","+oicq+","+icq+",'"+telnumber+"','"+comment+"',now(),'"+url+"' ,'"+email+"');";
sqlRst=sqlStmt.executeQuery (MyQuery); //向数据库中加入数据
sqlRst.close();//Weitere Informationen finden Sie hier
sqlStmt.close ();//Weitere Informationen
sqlConn.close(); //关闭数据库连接
out.print (Zeit);
%>
Fantastisches!
昵称:<%=username%> | 性别:<%=sex%> | Anzeige:<%=address %> | |
电话:<%=telnumber%> | Weitere Informationen:<%=post%> | OICQ:<%=oicq%> | ICQ:<%=icq%> |
E-Mail: | Anzeige: | ||
Vorlage:<%=comment%> -<%=time %>(来自<%=ip %>) |