當前位置:首頁 » 數據倉庫 » jsp留言板無資料庫
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

jsp留言板無資料庫

發布時間: 2022-12-24 21:55:43

① jsp不顯示資料庫內容,怎麼回事

有時候是在資料庫的剛剛進行更新的數據沒有提交。請提交後,在清除ie緩存或者重啟ie(重新開啟一個session)來刷新數據。應該就可以看到最新的數據了。

② 剛下載了一個深度學習(JSP)留言板,裡面的第二步說導入資料庫文件GuestBook_sql2000_DB_backup ,如何做到

這個是備份文件。在企業管理器中,選擇所有任務,還原資料庫就行了。

③ 怎麼樣用jsp做留言板啊 主要是不會在裡面寫有關於資料庫的東西

留言板要實現的功能是:瀏覽的人能留言並能分頁的查看留言,管理員能對留言進行處理!
這個留言板由9個小程序組成,分別是:board.jsp;message.html;opendata.jsp;manager.jsp;password.jsp;check.jsp;delete.jsp;convert.jsp
現在說第一個:board.jsp
他的任務是整個留言板的主程序,讓使用者留言,並提供分頁功能!
在開始之前,我們必須在mysql資料庫建立一個mydate的資料庫,在mudate中建立名為message的表:
mysql>create table message( name char(20),email char(40 ),subject char(60),time char(60),sex char(10),memo text,id int not null auto_increment,primary key(id));

board.jsp代碼:
<html>
<head>
<title>流言板</title>

</head>
<body>
<%@ page import="java.sql.*"%>
<%@ page contenttype="text/html;charset=gb2312"%>
<%@ include file="opendata.jsp"%>
<%
int count=0,lastp,numf,numl,prep,nextp,pageno;
if(request.getparameter("pageno")==null) //pageno:代表頁碼
pageno=0;
else
pageno=integer.parseint(request.getparameter("pageno"));
sql="select * from message";
rs=smt.executequery(sql);
while(rs.next())
count++; <%-- count:多少留言--%>
lastp=(int)math.ceil((double)count/5);
<%--用來計算此表中有幾頁留言:ceil返回大於等於其數字參數的最小整數。

math.ceil(number)

必選項number 參數是數值表達式。

說明
返回值為大於等於其數字參數的最小整數。 --%>
if(pageno==0||pageno>lastp)
pageno=lastp;
numf=pageno*5-4; <%--顯示留言的第一筆數據的編號_id--%>
numl=numf+4;<%--numl:此頁的最後的一筆數據編號id--%>
if(pageno==1)
prep=1; <%-- prep:上一頁--%>
else
prep=pageno-1;
if(pageno==lastp)
nextp=lastp;
else
nextp=pageno+1;
sql="select * from message where id between "+numf+" and "+numl;
rs=smt.executequery(sql);

%>

<font size=7 color=green>留言板</font>
<hr>
<center>
<form action=board.jsp method=post>
<table boder=0>
<tr>
<td>目前的頁次<font color=red><%=pageno%></font>/<font color=blue><%=lastp%></font></td>
<td><a href=board.jsp?pageno=<%=prep%>>[上一頁]</a></td>
<%--將參數pageno傳遞給程序,依據它來計算numl和numf,再將留言數據通過sql取出--%>
<td><a href=board.jsp?pageno=<%=nextp%>>[下一頁]</a></td>
<td><a href=board.jsp?pageno=1>[第一頁]</a></td>
<td><a href=board.jsp>[最後一頁]</a></td>
<td>輸入頁次<input type=text size=3 name=pageno></td>
<td><input type=submit name=send value=送出></td>
<td><a href=password.jsp><font color=red size="5"><i>站長專用</i></font></a></td>
</tr>
</table>
</form>
<%
string name,email,subject,time,sex,memo;
while(rs.next())
{
name=rs.getstring(1);
email=rs.getstring(2);
subject=rs.getstring(3);
time=rs.getstring(4);
sex=rs.getstring(5);
memo=rs.getstring(6);
out.print("<center>");
out.print("<table border=1>");
out.print("<tr><td bgcolor=yellow>姓名</td><td>"+name+"</td></tr>");
out.print("<tr><td bgcolor=yellow>e-mail</td><td>"+email+"</td></tr>");
out.print("<tr><td bgcolor=yellow>時間</td><td>"+time+"</td></tr>");
out.print("<tr><td bgcolor=yellow>主題</td><td>"+subject+"</td></tr>");
out.print("<tr><td bgcolor=yellow>留言</td><td>"+memo+"<img src="+sex+"></td></tr>");
out.print("</table><p>");

}
%>
<hr>
<center><a href="message.html">我要留言</a>
<a href=board.jsp>查看留言</a>

</body>
</html>

④ 如何在jsp網頁中添加留言板

在jsp網頁中添加留言板:
1、網頁里有可以添加的文本框等基本控制項
2、form表單提交給jsp的控制類寫入資料庫
3、網頁里讀取出留言的內容。

基本思路就是這樣的。

當然更簡單點的做法是寫好表單,把留言直接發到郵箱里去。jsp有個郵箱組件是jmail 你可以網路看看jmail如何使用。就可以簡單的完成留言功能,直接發郵箱不發到資料庫了。當然也同樣完成了保存留言的功能啦。

⑤ JSP留言板資料庫自動回復亂碼問題

應該是字元編碼的問題,你可以加個過濾器。
下面的代碼是tomcat里帶的一個例子。
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding right ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package filters;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;

/**
* <p>Example filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding. Configuration of this filter is based on
* the following initialization parameters:</p>
* <ul>
* <li><strong>encoding</strong> - The character encoding to be configured
* for this request, either conditionally or unconditionally based on
* the <code>ignore</code> initialization parameter. This parameter
* is required, so there is no default.</li>
* <li><strong>ignore</strong> - If set to "true", any character encoding
* specified by the client is ignored, and the value returned by the
* <code>selectEncoding()</code> method is set. If set to "false,
* <code>selectEncoding()</code> is called <strong>only</strong> if the
* client has not already specified an encoding. By default, this
* parameter is set to "true".</li>
* </ul>
*
* <p>Although this filter can be used unchanged, it is also easy to
* subclass it and make the <code>selectEncoding()</code> method more
* intelligent about what encoding to choose, based on characteristics of
* the incoming request (such as the values of the <code>Accept-Language</code>
* and <code>User-Agent</code> headers, or a value stashed in the current
* user's session.</p>
*
* @author Craig McClanahan
* @version $Revision: 466607 $ $Date: 2006-10-21 17:09:50 -0600 (Sat, 21 Oct 2006) $
*/

public class SetCharacterEncodingFilter implements Filter {

// ----------------------------------------------------- Instance Variables

/**
* The default character encoding to set for requests that pass through
* this filter.
*/
protected String encoding = null;

/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;

/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;

// --------------------------------------------------------- Public Methods

/**
* Take this filter out of service.
*/
public void destroy() {

this.encoding = null;
this.filterConfig = null;

}

/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {

// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}

// Pass control on to the next filter
chain.doFilter(request, response);

}

/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {

this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;

}

// ------------------------------------------------------ Protected Methods

/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* <code>null</code>.
* <p>
* The default implementation unconditionally returns the value configured
* by the <strong>encoding</strong> initialization parameter for this
* filter.
*
* @param request The servlet request we are processing
*/
protected String selectEncoding(ServletRequest request) {

return (this.encoding);

}

}
web.xml中的配置如下
<!-- Example filter to set character encoding on each request -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

⑥ 求jsp編寫的簡易留言板代碼!

LOGIN.JSP

<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>JSP+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>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>密 碼:</td>
<td><input 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>
<title>JSP+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>
<title>JSP+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>
<h3><a 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>
<title>JSP+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>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td>作者:</td>
<td><input type="text" name="author"></td>
</tr>
<tr>
<td>內容:</td>
<td><textarea 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>
<h3><a 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>
<title>JSP+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>
<title>JSP+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>
<h3><a 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>
<td><a href="update.jsp?id=<%=id%>"><%=title%></a></td>
<td><%=author%></td>
<td><%=content%></td>
<td><a 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>
<title>JSP+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>
<td><input type="text" name="title" value="<%=title%>"></td>
</tr>
<tr>
<td>作者:</td>
<td><input type="text" name="author" value="<%=author%>"></td>
</tr>
<tr>
<td>內容:</td>
<td><textarea 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)
{}
%>
<h3><a 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>
<title>JSP+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>
<title>JSP+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 ;

⑦ jsp留言板控制項

你用SOAOffice中間件吧,這是一個專門服務微軟Office的中間件,除了能在線編輯Word/Excel,電子印章、手寫批註,還能導入導出Word/Excel數據,完全後台代碼調用

⑧ JSP簡易留言板,不需要寫進資料庫,點擊「留言」後按後留言者在前顯示出來。捉急!

我已經做好了 只不過找不到 刷新的辦法!!!有缺陷

留言順序ABCDEFGHIJK

⑨ jsp頁面信息提交資料庫沒錯誤提示但是資料庫沒有數據!怎麼回事啊

如果是連接oracle,要這樣連:
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl為資料庫的SID
String user="test"; String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
其中你要把oracle的驅動文件,一個壓縮包放到工程的lib目錄下。
如果是連接mysql,就把forName里的換成是com.mysql.jdbc.Driver就行,然後也把相應的驅動載入到lib下
如果你的JdbcUtil已經封裝了這些東西也行。