⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 11-8.txt

📁 jsp常用实例讲解
💻 TXT
字号:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>留言簿</title>
<script language =JavaScript">
function newwin(url){
var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yew,width=600,height=450");
newwin.focus();
return false;
}
</script>
</head>

<body bgcolor="#FF66FF">
<script language="JavaScript">
function submit11(){
self.location.replace("bbs.jsp");
}
</script>

<div align="center">
<center>
<font color="blue" size="+3">留言簿</font>
<hr>

<%@ page import="java.sql.*" %>
<%-- 连接数据库使用的语句 --%>
<%
String url=new String();
String sql=new String();
url="jdbc:odbc:liuyan";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(url);
%>
<%-- 留言簿的留言信息分页显示,每页帖子的行数为6行 
totalSub  	留言数
totalRec  	总留言记录数
pageLine	每一页显示留言数
--%>
<%
int pageLine=6;
int totalRec=0;
int totalSub=0;
int intPage=1;
if(request.getParameter("page")!=null)
	intPage=Integer.parseInt(request.getParameter("page"));
Statement stat=conn.createStatement();
ResultSet countrs=null;
try{
	//从数据库中取得留言的总记录数
	countrs=stat.executeQuery("select count(*) as cnt from db2admin.guestbook");
	if(countrs.next())
		totalRec=countrs.getInt("cnt");
}catch(Exception e){
	e.printStackTrace();
}finally{
	countrs.close();
	stat.close();
}
//取得留言的总页数
int intPageCount=0;
intPageCount=(totalRec+pageLine-1)/pageLine;
%>

<table border="1" cellspacing="0" width="560" bgcolor="#F0F8FF" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF">
<tr align="center" bgcolor="#0099FF">
<td width="30">表情</td>
<td width="60">留言人</td>
<td width="60">留言时间</td>
<td width="410">留言内容</td>
</tr>
<%
//从数据库中取得留言的内容
int i=0;
int serial;
String emote="";
String name=new String();
String gettime=new String();
String content=new String();
Statement stat1=conn.createStatement();
ResultSet contentrs=null;

try{
	contentrs=stat1.executeQuery("select * from db2admin.guestbook order by serial_no DESC ");
	if(intPageCount>0){
		for(i=1;i<=(intPage-1)*pageLine;i++)
			contentrs.next();
		for(i=1;i<=pageLine;i++){
			if(contentrs.next()){
				emote=contentrs.getString("emote");
				name=contentrs.getString("name");
				gettime=contentrs.getString("guest_time");
				content=contentrs.getString("content");
%>
				<tr>
				<td width="30" align="center"><img src="images/<%=emote%>.gif"></td>
				<td width="60" align="center"><%=name%></td>
				<td width="60" align="center"><%=gettime%></td>
				<td width="410"><%=content%></td>
				</tr>
<%
			}
		}
		contentrs.next();
	}
}catch(Exception e){
	e.printStackTrace();
}finally{
	contentrs.close();
	stat1.close();
	conn.close();
}

%>
<%-- 分页显示帖子 --%>
<%
out.print("<TR>");
if(intPageCount*pageLine<totalRec)
	intPageCount++;
if(intPage>intPageCount)
	intPage=intPageCount;
if(intPage<1)
	intPage=1;
out.println("<form method=\"post\" name=fPageNum action=\"index.jsp\">");
out.println("<center>分页&nbsp;");
if(intPage<2)
	out.println("<font color=\"white\">首页 上一页</font>");
else{
	out.println("<a href=\"bbs.jsp?page=1\">首页</a>&nbsp;");
	out.println("<a href=\"bbs.jsp?page="+(intPage-1)+"\">上一页</a>&nbsp;");	
}
if(intPage-intPageCount>=0)
	out.println("<font color=\"white\">下一页 尾页</font>");
else
	out.println("<a href=\"bbs.jsp?page="+(intPage+1)+"\">下一页</a>&nbsp;<a href=\"bbs.jsp?page="+intPageCount+"\">尾页</a>");
out.print("&nbsp;页次:<strong><font color=\"white\">"+intPage+"</font>/"+intPageCount+"</strong>页");
out.print("&nbsp;共<b>"+totalRec+"</b>条留言<b> "+pageLine+" </b>条/页");
out.print("&nbsp;&nbsp;转到第<input type=\"text\" name=\"page\" size=\"2\" maxlength=\"10\" class=smallInput value=\""+intPage+"\">");
out.print("页<input class=buttonface type=\"submit\" value=\"GO\" name=\"cndok\"></span></p></form>");
out.print("</td>");
out.print("</tr>");
%>

</table>
<p align="center">
<form action="search.jsp" method="POST" name="search" target="_blank">
<font color="blue">[ 查询留言 ]</font>
<input type="text" name="keywords" size="10">
<input type="submit" name="submit" value="查询" >&nbsp;&nbsp;&nbsp;
<a href="write.jsp" onClick=" return newwin(this.href);">[ 留言 ]</a>&nbsp;&nbsp;
<a href="manage.jsp" onClick=" return newwin(this.href);">[ 留言管理 ]</a>&nbsp;&nbsp;
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -