商业源码热门下载www.html.org.cn
package guestbook;
import java.sql.*;
public class guestbook{
string sdbdriver = "sun.jdbc.odbc.jdbcodbcdriver";
string sconnstr = "jdbc:odbc:guestbook";
connection conn = null;
resultset rs = null;
public guestbook() {
try {
class.forname(sdbdriver);
}
catch(java.lang.classnotfoundexception e) {
system.err.println("guestbook(): " + e.getmessage());
}
}
public void executeinsert(string sql) {
try {
conn = drivermanager.getconnection(sconnstr);
statement stmt = conn.createstatement();
stmt.executeupdate(sql);
}
catch(sqlexception ex) {
system.err.println("guestbook.executeupdate: " + ex.getmessage());
}
}
public resultset executequery(string sql) {
rs = null;
try {
conn = drivermanager.getconnection(sconnstr);
statement stmt = conn.createstatement();
rs = stmt.executequery(sql);
}
catch(sqlexception ex) {
system.err.println("guestbook.executequery: " + ex.getmessage());
}
return rs;
}
}
<html>
<head>
<title>my first jsp guestbook</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#ccccff" vlink="#000000" alink="#666666">
<div align="center">
<p><font size="7"><b><font size="+6">jsp guestbook</font></b></font></p>
<form method="post" action="index.jsp">
<table width="75%" align="center" border=1>
<tr>
<td width="30%">
<div align="right">name:</div>
</td>
<td width="70%">
<input type="text" name="name">
</td>
</tr>
<tr>
<td width="30%">
<div align="right">e-mail:</div>
</td>
<td width="70%">
<input type="text" name="email">
</td>
</tr>
<tr>
<td width="30%">
<div align="right">site url:</div>
</td>
<td width="70%">
<input type="text" name="url" value="http://">
</td>
</tr>
<tr>
<td width="30%">
<p>what do you want to</p>
<p>say?</p>
</td>
<td width="70%">
<textarea name="body" rows="5" cols="30"></textarea>
</td>
</tr>
<tr>
<td width="30%"> </td>
<td width="70%"> </td>
</tr>
<tr>
<td width="30%"> </td>
<td width="70%">
<table width="75%">
<tr>
<td>
<input type="submit" name="send" value="send">
</td>
<td>
<input type="reset" name="reset" value="reset">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<hr>
<%@ page language="java" import="java.sql.*" %>
<jsp:usebean id="sqlbean" scope="page" class="guestbook.guestbook" />
<%! string name,email,url,body,sql; %>
<%
if (name!=null&&email!=null&&body!=null)
{
name = request.getparameter("name");
email = request.getparameter("email");
url = request.getparameter("url");
body = request.getparameter("body");
sql = "insert into guestbook (name,email,url,body)
values( "+name+" , "+email+" , "+url+" , "+body+" )";
sqlbean.executeinsert(sql);
}else{
out.print("<b><font color=red>sorry, please enter your name,email and body!!!</font></b>");
}
%>
<p><font size="4"><b><a href="./index.jsp#see">see my guestbook</a></b></font></p>
<%-- because i don t konw a good method to konw the all items count,so.... --%>
<%
// resultset rscount = sqlbean.executequery("select count(*) from guestbook");
resultset rscount = sqlbean.executequery("select * from guestbook");
int i=0;
while (rscount.next()) {
i++;
}
%>
<%-- <p><a name=see><b>now,<%= rscount %> records.</b><a></p> --%>
<p><a name=see><b>now,<%= i %> records.</b><a></p>
<%
rscount.close();
i=0;
%>
<p> </p>
<%
resultset rs = sqlbean.executequery("select * from guestbook order by recordid desc");
while (rs.next()){
name = rs.getstring("name");
email = rs.getstring("email");
url = rs.getstring("url");
body = rs.getstring("body");
%>
<table border=1 width=80%>
<tr>
<td width=30%>name:</td><td width=70%><%= name %>
</tr>
<tr>
<td width=30%>email:</td><td width=70%><a href="mailto:<%= email %>"><%= email %></a></td>
</tr>
<tr>
<td width=30%>siteurl:</td><td width=70%><a href="<%= url %>"><%= url %></a></td>
</tr>
<tr>
<td width=30%>body:</td><td width=70%><%= body %></td>
</tr>
</table>
<hr>
<%
}
rs.close();
%>
</div>
</body>
</html>
新闻热点
疑难解答