科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道应用软件JSP记事本程序

JSP记事本程序

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

JSP记事本程序。

作者:axeon 来源:天极网 2007年10月30日

关键字: JSP 记事本 程序

  • 评论
  • 分享微博
  • 分享邮件

在本页阅读全文(共19页)

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>

查看本文来源

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章