码迷,mamicode.com
首页 > 其他好文 > 详细

简单BBS项目

时间:2014-05-01 18:42:33      阅读:434      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   java   tar   ext   javascript   width   color   get   

项目的基本要求:  

  掌握递归
  掌握JavaScript+html+css+jsp+servlet初步应用
  掌握分页写法
  初步掌握前台/后台的概念

简单的功能需求:
  1.能够树形展现
  2.能够平板型展现
  3.能够回复帖子
  4.后台能够管理帖子,如:删除

<1.新建项目:右键new/project/Dynamic Web Project,项目名称为BBS,配置tomcat。

<2.设计数据库的表:保留建表的语句到项目中,在项目new/folder然后引入bbs.sql;

*****bbs.sql*****

create database bbs;

use bbs;

create table article
(
id int primary key auto_increment, //auto_increment--为mysql中的自动递增
pid int,
rootid int,
title varchar(255),
cont text,
pdate datetime,
isleaf int
);

insert into article values (null, 0, 1, ‘蚂蚁大战大象‘, ‘蚂蚁大战大象‘, now(), 1); //因为第一个字段自动递增,所以为null值
insert into article values (null, 1, 1, ‘大象被打趴下了‘, ‘大象被打趴下了‘,now(), 1);
insert into article values (null, 2, 1, ‘蚂蚁也不好过‘,‘蚂蚁也不好过‘, now(), 0);
insert into article values (null, 2, 1, ‘瞎说‘, ‘瞎说‘, now(), 1);
insert into article values (null, 4, 1, ‘没有瞎说‘, ‘没有瞎说‘, now(), 0);
insert into article values (null, 1, 1, ‘怎么可能‘, ‘怎么可能‘, now(), 1);
insert into article values (null, 6, 1, ‘怎么没有可能‘, ‘怎么没有可能‘, now(), 0);
insert into article values (null, 6, 1, ‘可能性是很大的‘, ‘可能性是很大的‘, now(), 0);
insert into article values (null, 2, 1, ‘大象进医院了‘, ‘大象进医院了‘, now(), 1);
insert into article values (null, 9, 1, ‘护士是蚂蚁‘, ‘护士是蚂蚁‘, now(), 0);

批量输入以上语句:进入mysql后台,执行命令:source */bbs.sql //*代表相应的目录
mysql的账号/密码
还要在项目的WebContentde/WEB-INF/LIB中引入mysql-connector-java-5.1.29-bin.jar包

<3.在eclipse中直接查看数据库
在Data Source Explorer中右键点击DataBase/new-->选择Generic JDBC Connection-->随便输入名称然后next-->选择相应的数据库......

<4.新建JSP文件ShowArticleTree.jsp

-----ShowArticleTree.jsp-----

<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@page import="java.sql.*"%>

<%
String admin=(String)session.getAttribute("admin"); //在Login.jsp中session.setAttribute("admin","true");-----由此判断是否在登录页面Login.jsp中成功登录
if(admin!=null&&admin.equals("true")){
login=true; //登录成功则讲login设置为true
}
%>

<%!
String str="";
boolean login=false; //设置变量login,判断是否登录
private void tree(Connection conn,int id,int level){
Statement stmt=null;
ResultSet rs=null;
String preStr="";
for(int i=0;i<level;i++){
preStr+="----";
}
try{
stmt=conn.createStatement();
String sql="select * from article where pid ="+id;
String strLogin="";
rs=stmt.executeQuery(sql);
while(rs.next()){
if(login){ //判断是否成功登录
strLogin="<td><a href=‘Delete.jsp?id="+rs.getInt("id")+"&pid="+rs.getInt("pid")+"‘>delete</a>"; //设置删除链接
}
str+="<tr><td>"+rs.getInt("id")+"</td><td>"+
"<a href=‘ShowArticleDetail.jsp?id="+rs.getInt("id")+"‘>"+rs.getString("title")+"</a>"+strLogin+"</td></tr>"; //若成功登录,则加上删除链接
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"),level+1);
}
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
%>

<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/bbs?user=root&password=abc123";
Connection conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from article where pid=0");
String strLogin="";
while(rs.next()){
if(login){
strLogin="<td><a href=‘Delete.jsp?id="+rs.getInt("id")+"&pid="+rs.getInt("pid")+"‘>delete</a>";
}
str+="<tr><td>"+rs.getInt("id")+"</td><td>"+"<a href=‘ShowArticleDetail.jsp?id="+rs.getInt("id")+"‘>"+rs.getString("title")+"</a>"+"</a></td>"+strLogin+"</td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"),1);
}
}
rs.close();
stmt.close();
conn.close();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<%=str %>
</table>
</body>
</html>

<5.用递归的方法输出树:

-----ShowArticleTree.jsp-----

<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@page import="java.sql.*"%>

<%!  //定义地柜函数来显示树状的帖子
String str=""; 
private void tree(Connection conn,int id,int level){
Statement stmt=null;
ResultSet rs=null;
String preStr="";
for(int i=0;i<level;i++){
preStr+="----";
}
try{
stmt=conn.createStatement();
String sql="select * from article where pid ="+id;
rs=stmt.executeQuery(sql);
while(rs.next()){
str+="<tr><td>"+rs.getInt("id")+"</td><td>"+"<a href=‘ShowArticleDetail.jsp?id="+rs.getInt("id")+"‘>"+rs.getString("title")+"</a>"+"</a></td>"+"<td><a href=‘Delete.jsp?id="+rs.getInt("id")+"&pid="+rs.getInt("pid")+"‘>删除</a>"+"</td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"),level+1);
}
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
%>

<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/bbs?user=root&password=abc123";
Connection conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from article where pid=0");
while(rs.next()){
str+="<tr><td>"+rs.getInt("id")+"</td><td>"+"<a href=‘ShowArticleDetail.jsp?id="+rs.getInt("id")+"‘>"+rs.getString("title")+"</a>"+"</a></td>"+"<td><a href=‘Delete.jsp?id="+rs.getInt("id")+"&pid="+rs.getInt("pid")+"‘>删除</a>"+"</td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"),1);
}
}
rs.close();
stmt.close();
conn.close();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<%=str %>
<%str=""; %> //将字符串置为空,避免刷新时重复显示
</table>
</body>
</html>

<6.创建jsp文件显示帖子的具体内容(从数据库中取内容)

-----ShowArticleDetil.jsp-----

<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
String strid=request.getParameter("id"); //获得ShowArticleTree.jsp的表格链接过来的id
int id=Integer.parseInt(strid); //将获得字符串转为Int

Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/bbs?user=root&password=abc123";
Connection conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from article where id="+id);

%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<%
if(rs.next()){
%>
<table border="1">
<tr>
<td>Id</td>
<td><%=rs.getInt("id") %></td>
</tr>
<tr>
<td>Title</td>
<td><%=rs.getString("id") %></td>
</tr>
<tr>
<td>Context</td>
<td><%=rs.getString("cont") %></td>
</tr>
</table>
<a href="Reply.jsp?id=<%=rs.getInt("id")%>&rootid=<%=rs.getInt("rootid")%>">回复</a> //在帖子的细节中加入回复功能,链接到Reply.jsp,其中传入参数id和rootid
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

<7.加入回复功能:

------Reply.jsp-----

<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>

<%
int id=Integer.parseInt(request.getParameter("id")); //接收ShowArticleDetil.jsp传过来的参数
int rootid=Integer.parseInt(request.getParameter("rootid")); //接收ShowArticleDetil.jsp传过来的参数
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>

<script language="javascript">
<!--
//javascript去空格函数
function LTrim(str){ //去掉字符串 的头空格
var i;
for(i=0;i<str.length; i++) {
if(str.charAt(i)!=" ") break;
}
str = str.substring(i,str.length);
return str;
}

function RTrim(str){
var i;
for(i=str.length-1;i>=0;i--){
if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;
}
str = str.substring(0,i+1);
return str;
}
function Trim(str){

return LTrim(RTrim(str));

}

function check() {
if(Trim(document.reply.title.value) == "") {
alert("please intput the title!");
document.reply.title.focus();
return false;
}

if(Trim(document.reply.cont.value) == "") {
alert("plsease input the content!");
document.reply.cont.focus();
return false;
}

return true;

}
-->
</script>

</head>
<body>
<form action="ReplyOK.jsp" method="post" onsubmit="return check()"> //当点击提交时转到ReplyOK.jsp页面;提交前调用函数check()验证内容是否正确,正确则成功提交,否则无法提交
<input type="hidden" name="id" value="<%=id %>"> //以隐藏域的方式传递参数
<input type="hidden" name="rootid" value="<%=rootid %>"> //以隐藏域的方式传递参数
<table border="1">
<tr>
<td>
<input type="text" name="title" size="80">
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows=12 name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>

</body>
</html>

-----ReplyOK.jsp-----

<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*"%>

<%
request.setCharacterEncoding("gbk"); //解决中文字符问题,上一个页面默认按ISO-8859-1提交过来,将其改为GBK编码

int id=Integer.parseInt(request.getParameter("id"));
int rootid=Integer.parseInt(request.getParameter("rootid"));
String title=request.getParameter("title");

if(title==null){ //服务器验证是否正确
out.println("error!please use my bbs in the right way!");
return;
}

title=title.trim();

if(title.equals("")){ //服务器验证是否正确
out.println("title could not be empty!");
return;
}

String cont=request.getParameter("cont");
cont=cont.trim();

if(cont.equals("")){ //服务器验证是否正确
out.println("content could not be empty!");
return;
}

String cont=request.getParameter("cont");
cont=cont.replaceAll("\n","<br>"); //解决无法显示换行问题,将java中的换行"\n"替换为页面显示的换行"<br>"

Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/bbs?user=root&password=abc123";
Connection conn=DriverManager.getConnection(url);

conn.setAutoCommit(false); //避免不同步--插入帖子和更新被回复帖子为非叶子节点必须同步完成

String sql="insert into article values(null,?,?,?,?,now(),0)"; //在数据库中插入刚刚回复的新帖子--**注意这一中输入数据库的技巧
PreparedStatement pstmt=conn.prepareStatement(sql);
Statement stmt=conn.createStatement();
pstmt.setInt(1,id);
pstmt.setInt(2,rootid);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.executeUpdate();

stmt.executeUpdate("update article set isleaf=1 where id="+id); //更新被回复帖子为非叶子节点

conn.commit(); //避免不同步,在完成上面两步之后才自己提交
conn.setAutoCommit(true); //恢复现场

stmt.close();
pstmt.close();
conn.close();

response.sendRedirect("ShowArticleTree.jsp"); //提交成功后转到ShowArticleTree.jsp页面
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

<7.增加删除功能:

-----Delete.jsp-----

<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*"%>

<%!
private void del(Connection conn,int id){ //定义递归函数删除节点及其子节点
Statement stmt=null;
ResultSet rs=null;
try{
stmt=conn.createStatement();
String sql="select * from article where pid ="+id;
rs=stmt.executeQuery(sql);
while(rs.next()){
del(conn,rs.getInt("id"));
}
stmt.executeUpdate("delete from article where id="+id);
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
%>

<%
String admin=(String)session.getAttribute("admin"); //增加验证功能,不登录则不可以浏览Delete.jsp页面(与前面的ShowArticleTree.jsp中的类似)
if(admin!=null&&admin.equals("false")){
out.println("小子,别想通过我这关!");
return; //直接结束,后面的内容不显示
}
%>

<%
int id=Integer.parseInt(request.getParameter("id"));
int pid=Integer.parseInt(request.getParameter("pid"));

Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/bbs?user=root&password=abc123";
Connection conn=DriverManager.getConnection(url);

conn.setAutoCommit(false); //避免不同步,设置trasaction

del(conn,id);

Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select count(*) from article where pid="+pid); //得到父节点为pid的所有子节点的数目
rs.next();
int count=rs.getInt(1); //获得第1列的值
rs.close();
stmt.close();

if(count<=0){
Statement stmtUpdate=conn.createStatement();
stmtUpdate.executeUpdate("update article set isleaf=0 where id="+pid); //将父节点设为叶子节点
stmtUpdate.close();
}

conn.commit();
conn.setAutoCommit(true);
conn.close();


response.sendRedirect("ShowArticleTree.jsp");
%>

<8.增加只有管理员可以删除功能,还有增加主题的功能:

-----Post.jsp-----

<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@page import="java.sql.*" %>

<%
String action=request.getParameter("action");
if(action!=null&&action.equals("post")){ //判断是又发新帖(方式为get)转到的还是自身点提交(方式为post)转到这页面的

String title=request.getParameter("title");
String cont=request.getParameter("cont");

cont=cont.replaceAll("\n","<br>");

Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/bbs?user=root&password=abc123";
Connection conn=DriverManager.getConnection(url);

conn.setAutoCommit(false);

String sql="insert into article values(null,0,?,?,?,now(),0)";
PreparedStatement pstmt=conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS); //利用Statement.RETURN_GENERATED_KEYS告诉JDBC,这个sql语句中有自动增加的字段
Statement stmt=conn.createStatement();

pstmt.setInt(1,-1);
pstmt.setString(2,title);
pstmt.setString(3,cont);
pstmt.executeUpdate();

ResultSet rsKey=pstmt.getGeneratedKeys(); //获得这些自动增加的字段的值
rsKey.next();
int key=rsKey.getInt(1); //获得第一个自动增加的字段的值
rsKey.close();
stmt.executeUpdate("update article set rootid="+key+"where id="+key); //更新rootid的值

//stmt.executeUpdate("update article set isleaf=1 where id="+id);

conn.commit();
conn.setAutoCommit(true);

stmt.close();
pstmt.close();
conn.close();

response.sendRedirect("ShowArticleTree.jsp");
}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<form action="Post.jsp" method="post">
<input type="hidden" name="action" value="post"> //设置隐藏域,跟上面的语句来配合区分是由哪个页面转到这里的
<table border="1">
<tr>
<td>
<input type="text" name="title" size="80">
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows=12 name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>

</body>
</html>

-----Login.jsp-----
在WebContent中新建文件夹images,引入所有图片;并引入login.jsp到WebContent。账号密码都是admin

<%@ page contentType="text/html; charset=gbk" pageEncoding="gbk" %>

<%
String action = request.getParameter("action");
if(action != null && action.equals("login")) {
String username = request.getParameter("uname"); //获得账号
String password = request.getParameter("pwd"); //获得密码
if(username == null || !username.equals("admin")) {
%>
<font color="white" size=5>username not correct!</font>
<%
//return;-----表示页面到此结束,后面不显示
}else if(password == null || !password.equals("admin")) {
out.println("password not correct!");
//return;-----表示页面到此结束,后面不显示
}else {
session.setAttribute("admin", "true");
response.sendRedirect("ShowArticleTree.jsp");
}
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0054)http://www.simworld.com/client_access/client_login.asp -->
<HTML><HEAD><TITLE>SIM - Client Access - Login</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gbk" pageEncoding="gbk"><LINK
href="images/sim_stylesheet.css" type=text/css
rel=styleSheet>
<SCRIPT language=JavaScript src="" type=text/javascript></SCRIPT>

<SCRIPT language=JavaScript src="" type=text/javascript></SCRIPT>

<SCRIPT language=JavaScript src="" type=text/javascript></SCRIPT>

<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<style type="text/css">
<!--
.STYLE1 {color: #CCCCCC}
-->
</style>

</HEAD>
<BODY bgColor=#20355a leftMargin=0 topMargin=0 onload=init() marginheight="0"
marginwidth="0"><!--Begin all TOP NAVIGATIOND ROPDOWN LAYERS ------------><!--Begin About Sim Dropdown 1 -->
<DIV id=about_sim_drop1>
<TABLE cellSpacing=0 cellPadding=0 width=140 border=0>
<TBODY>
<TR>
<TD bgColor=#ffffff>
<TABLE cellSpacing=2 cellPadding=2 width=140 border=0>
<TBODY>
<TR>
<TD vAlign=top align=left width=130><A class="topnav"
onmouseover="stopTime(); showLayer(‘about_sim_corporate_drop2‘); hideLayer(‘about_sim_portfolio_drop2‘);"
onmouseout=startTime();
href="http://www.simworld.com/about_sim/corporate/index.asp">Corporate
Info</A></TD>
<TD vAlign=top width=10><IMG height=10 alt=arrow
src="images/nav_arrows.gif"
width=10></TD></TR></TBODY></TABLE></TD></TR><!--
<tr>
<td bgcolor="#CACFDA">
<table width="140" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="130" valign="top" align="left"><a href="/about_sim/services/index.asp" onMouseOver="stopTime(); hideLayer(‘about_sim_corporate_drop2‘);" onMouseOut="startTime();" class="topnav">Services</a></td>
<td width="10" valign="top"><img src="/pics/spacer.gif" width="10" height="10"></td>
</tr>
</table>
</td>
</tr>
-->
<TR>
<TD bgColor=#cacfda>
<TABLE cellSpacing=2 cellPadding=2 width=140 border=0>
<TBODY>
<TR>
<TD vAlign=top align=left width=130><A class="topnav"
onmouseover="stopTime(); hideLayer(‘about_sim_corporate_drop2‘);"
onmouseout=startTime();
href="http://www.simworld.com/about_sim/products/index.asp">Products</A></TD>
<TD vAlign=top width=10><IMG height=10
src="images/spacer.gif"
width=10></TD></TR></TBODY></TABLE></TD></TR><!--<tr>
<td bgcolor="#CACFDA">
<table width="140" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="130" valign="top" align="left"><a href="/about_sim/portfolio/index1.asp" onMouseOver="stopTime(); showLayer(‘about_sim_portfolio_drop2‘); hideLayer(‘about_sim_corporate_drop2‘);" onMouseOut="startTime();" class="topnav">Portfolio</a></td>
<td width="10" valign="top"><img src="/pics/nav_arrows.gif" alt="arrow" width="10" height="10"></td>
</tr>
</table>
</td>
</tr>-->
<TR>
<TD bgColor=#ffffff>
<TABLE cellSpacing=2 cellPadding=2 width=140 border=0>
<TBODY>
<TR>
<TD vAlign=top align=left width=130><A class="topnav"
onmouseover=stopTime();
onmouseout="startTime(); hideLayer(‘about_sim_corporate_drop2‘);"
href="http://www.simworld.com/about_sim/portfolio/index_temp.asp">Portfolio</A></TD>
<TD vAlign=top width=10><IMG height=10 alt=arrow
src="images/spacer.gif"
width=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV><!-- End About Sim Dropdown 1 --><!--Begin About Sim Corporate Dropdown 2 -->
<DIV id=about_sim_corporate_drop2>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD bgColor=#cacfda>
<TABLE cellSpacing=2 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=left width="100%"><A class="topnav"
onmouseover=stopTime(); onmouseout=startTime();
href="http://www.simworld.com/about_sim/corporate/mission.asp">Mission</A></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#ffffff>
<TABLE cellSpacing=2 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=left width="100%"><A class="topnav"
onmouseover=stopTime(); onmouseout=startTime();
href="http://www.simworld.com/about_sim/corporate/philosophy.asp">Philosophy</A></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#cacfda>
<TABLE cellSpacing=2 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=left width="100%"><A class="topnav"
onmouseover=stopTime(); onmouseout=startTime();
href="http://www.simworld.com/about_sim/corporate/team.asp">Team</A></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#ffffff>
<TABLE cellSpacing=2 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=left width="100%"><A class="topnav"
onmouseover=stopTime(); onmouseout=startTime();
href="http://www.simworld.com/about_sim/corporate/specialty.asp">Specialty
Markets </A></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#cacfda>
<TABLE cellSpacing=2 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=left width="100%"><A class="topnav"
onmouseover=stopTime(); onmouseout=startTime();
href="http://www.simworld.com/about_sim/corporate/news.asp">News
&amp; Awards</A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV><!--Begin About Sim Corporate Dropdown 2 --><!--Begin About Sim Portfolio Dropdown 2 -->
<DIV id=about_sim_portfolio_drop2><!--<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#CACFDA">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top" align="left"><a href="/about_sim/portfolio/websites.asp" onMouseOver="stopTime();" onMouseOut="startTime();" class="topnav">Websites</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top" align="left"><a href="/about_sim/portfolio/multimedia.asp" onMouseOver="stopTime();" onMouseOut="startTime();" class="topnav">Multimedia Presentations</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#CACFDA">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top" align="left"><a href="/about_sim/portfolio/print_graphic_design.asp" onMouseOver="stopTime();" onMouseOut="startTime();" class="topnav" target="_blank">Print / Graphic Design</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top" align="left"><a href="/about_sim/client_list.pdf" onMouseOver="stopTime();" onMouseOut="startTime();" class="topnav" target=_"blank">Client List (PDF)</a></td>
</tr>
</table>
</td>
</tr>
</table>--></DIV><!--Begin About Sim Portfolio Dropdown 2 --><!--Begin Client Access Dropdown 1 -->
<DIV id=client_access_drop1><!--<table width="140" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF">
<table width="140" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="130" valign="top" align="left"><a href="/client_access/client_login.asp" onMouseOver="stopTime(); hideLayer(‘client_access_customer_drop2‘);" onMouseOut="startTime();" class="topnav">Client Login</a></td>
<td width="10" valign="top"><img src="/pics/spacer.gif" width="10" height="10"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#CACFDA">
<table width="140" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="130" valign="top" align="left"><a href="/client_access/customerservice/index1.asp" onMouseOver="stopTime(); showLayer(‘client_access_customer_drop2‘);" onMouseOut="startTime();" class="topnav">Customer Service</a></td>
<td width="10" valign="top"><img src="/pics/nav_arrows.gif" alt="arrow" width="10" height="10"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="140" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="130" valign="top" align="left"><a href="/under_construction.asp" onMouseOver="stopTime(); hideLayer(‘client_access_customer_drop2‘);" onMouseOut="startTime();" class="topnav">Beyond Today</a></td>
<td width="10" valign="top"><img src="/pics/spacer.gif" width="10" height="10"></td>
</tr>
</table>
</td>
</tr>
</table>--></DIV><!-- End Client Access Dropdown 1 --><!--Begin Client Access Customer Service Dropdown 2 -->
<DIV id=client_access_customer_drop2><!--<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#CACFDA">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top" align="left"><a href="/client_access/customerservice/policy1.asp" onMouseOver="stopTime();" onMouseOut="startTime();" class="topnav">Our Policy</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top" align="left"><a href="/client_access/customerservice/help1.asp" onMouseOver="stopTime();" onMouseOut="startTime();" class="topnav">Help</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#CACFDA">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top" align="left"><a href="/client_access/customerservice/downloads1.asp" onMouseOver="stopTime();" onMouseOut="startTime();" class="topnav">Downloads</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top" align="left"><a href="/client_access/customerservice/tech_standards1.asp" onMouseOver="stopTime();" onMouseOut="startTime();" class="topnav" target=_"blank">Technical Standards</a></td>
</tr>
</table>
</td>
</tr>
</table>--></DIV><!-- End Client Access Customer Service Dropdown 2 --><!--Begin Join our Team Dropdown 1 -->
<DIV id=join_our_team_drop1>
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TBODY>
<TR>
<TD bgColor=#ffffff>
<TABLE cellSpacing=2 cellPadding=2 width=150 border=0>
<TBODY>
<TR>
<TD vAlign=top width=10><IMG height=10
src="images/client_access.htm"
width=10></TD>
<TD vAlign=top align=right width=140><A class="topnav"
onmouseover=stopTime(); onmouseout=startTime();
href="http://www.simworld.com/join_our_team/job_openings.asp">Job
Openings</A></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#cacfda>
<TABLE cellSpacing=2 cellPadding=2 width=150 border=0>
<TBODY>
<TR>
<TD vAlign=top width=10><IMG height=10
src="images/spacer.gif" width=10></TD>
<TD vAlign=top align=right width=140><A class="topnav"
onmouseover=stopTime(); onmouseout=startTime();
href="http://www.simworld.com/join_our_team/apply_online.asp">Employee
Benefits</A></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#ffffff>
<TABLE cellSpacing=2 cellPadding=2 width=150 border=0>
<TBODY>
<TR>
<TD vAlign=top width=10><IMG height=10
src="images/spacer.gif" width=10></TD>
<TD vAlign=top align=right width=140><A class="topnav"
onmouseover=stopTime(); onmouseout=startTime();
href="http://www.simworld.com/join_our_team/corp_culture.asp">Corporate
Culture</A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV><!-- End Join Our Team Dropdown 1 --><!--End all TOP NAVIGATIOND ROPDOWN LAYERS ------------><!--Begin Browser Spanning Table, this allows Main Web Site Table to be centered in the middle of the browser -->
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center
border=0>
<TBODY>
<TR>
<TD><!--Begin Main Web Site Table All Website Design elements below-->
<TABLE borderColor=#ffffff cellSpacing=0 cellPadding=0 width=760
align=center border=1>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><!-- Begin Top Logo, Navigation and Message bar Table -->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><!--Beign Global Nav Buttons --->
<TBODY>
<TR>
<TD rowSpan=2><IMG height=53
alt="Screened Images Multimedia"
src="images/sim_logo_top.gif"
width=136 useMap=#top_logo_map border=0><MAP
name=top_logo_map><AREA shape=RECT
alt="Screened Images Multimedia [Back to Home]"
coords=11,4,120,54
href="http://www.simworld.com/index.asp"></MAP></TD>
<TD><span class="STYLE1">&#27426;&#36814;&#26469;&#21040;
&#33879;&#21517;&#30340;BBS&#21518;&#21488;</span></TD>
</TR>
<TR><!--End Global Nav Buttons --->
<TD><span class="STYLE1">&#19981;&#36755;&#20837;&#29992;&#25143;&#21517;&#23494;&#30721;&#19981;&#35768;&#36827; &#29992;&#25143;&#21517;: admin &#23494;&#30721;: admin </span></TD>
</TR></TBODY></TABLE><!-- End Top Logo, Navigation and Message bar Table --></TD></TR>
<TR>
<TD><!-- Begin Inner Content Table: This portion will be customizable throughout the website -->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=324
src="images/client_login_left_arc.gif"
width=137 useMap=#bot_logo_map border=0><MAP
name=bot_logo_map><AREA shape=RECT
alt="Screened Images Multimedia [Back to Home]"
coords=11,0,120,24
href="http://www.simworld.com/index.asp"></MAP></TD>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD><IMG height=91 alt="CLIENT LOG-IN"
src="images/client_login_title.gif"
width=282></TD></TR>
<TR>
<TD>
<FORM action=Login.jsp method=post>
<input type=hidden name=action value=login>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/client_login_text_bg.gif"
border=0>
<TBODY>
<TR>
<TD rowSpan=4><IMG height=158
src="images/spacer.gif"
width=22 border=0></TD>
<TD colSpan=2>
<P class="bodydarkblue">Please enter your username
and password here to preview your designs, check
project status and/or submit new job
requests.</P></TD></TR>
<TR>
<TD>
<P class="bodyldarkblue"><LABEL
for=uname>用户名:</LABEL></P></TD>
<TD><INPUT id=uname name=uname></TD></TR>
<TR>
<TD>
<P class="bodyldarkblue"><LABEL
for=pwd>密码:</LABEL></P></TD>
<TD><INPUT id=pwd type=password
name=pwd></TD></TR>
<TR>
<TD vAlign=top colSpan=2><A class="bodydarkblue"
href="http://www.simworld.com/client_access/client_login.asp"><STRONG><!--Forget your password?--></STRONG></A><IMG
height=1
src="images/spacer.gif"
width=132
border=0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT
type=image alt=Submit
src="images/client_login_submit.gif"
align=absMiddle value=Submit
name=Submit></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><IMG height=75
src="images/client_login_bot_arc.gif"
width=282></TD></TR></TBODY></TABLE></TD>
<TD><IMG height=324 alt="Log-in Image"
src="images/client_login_main_pic.jpg"
width=341></TD></TR></TBODY></TABLE><!-- End Inner Content Table --------></TD></TR>
<TR>
<TD><!-- Begin Bottom Navigation: Contact Us, Request A- Quote -->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><A
onmouseover="Rollover(‘nav_homepage_a‘,‘nav_homepage‘);"
onmouseout="Rollover(‘nav_homepage‘,‘nav_homepage‘);"
href="http://www.simworld.com/index.asp"></A><IMG height=26

src="images/interior_bot_nav_bar.gif"
width=100%></TD>
</TR>
<TR>
<TD><IMG height=12
alt="Copyright 2003 Screened Images, Inc."
src="images/bot_footer_bar.gif"
width=760></TD></TR></TBODY></TABLE><!-- End Bottom Navigation: Contact Us, Request A- Quote --></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><!--End Main Web Site Table --></TD></TR></TBODY></TABLE><!--End Browser Spanning Table --></BODY></HTML>

<9.平板显示模式的BBS

-----ShowArticleFlat.jsp-----

<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@page import="java.sql.*"%>

<% //实现分页功能
int pageSize=3; //设置每页显示条数为3

String strPageNo=request.getParameter("pageNo"); //获得想要显示的页数
int pageNo;
if(strPageNo==null||strPageNo.equals("")){
pageNo=1;
}else{
pageNo=Integer.parseInt(strPageNo.trim());
if(pageNo<=0) pageNo=1;
}
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/bbs?user=root&password=abc123";
Connection conn=DriverManager.getConnection(url);

Statement stmtCount=conn.createStatement();
ResultSet rsCount=stmtCount.executeQuery("select count(*) from article where pid=0");
rsCount.next();
int totalRecords=rsCount.getInt(1); //获得总共有多少条帖子

int totalPages=(totalRecords%pageSize==0?totalRecords/pageSize:totalRecords/pageSize+1); //获得总共多少页
if(pageNo>=totalPages) pageNo=totalPages; //若当前页大于总共页数,将当前页数设置为总共页数
int startPos=(pageNo-1)*pageSize;
Statement stmt=conn.createStatement();
ResultSet rsCount=stmtCount.executeQuery("select count(*) from article where pid=0");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
<a href="Post.jsp">发表新帖</a> //点击发表新帖转到Post.jsp
<table border="1">

<%
while(rs.next()){
%>

<tr>
<td>
<%=rs.getString("cont") %> //获得cont的内容,以平板的形式显示(更改上面的Post.jsp-----重定向到ShowArticleFlat.jsp)
</td>
</tr>

<%
}
rs.close();
stmt.close();
conn.close();
%>

</table>
第<%=pageNo %>页 共<%=totalPages %>页&nbsp //显示当前页码,与总共页数
<a href="ShowArticleFlat.jsp?pageNo=<%=pageNo-1 %>">上一页</a>&nbsp&nbsp&nbsp //实现功能上一页
<a href="ShowArticleFlat.jsp?pageNo=<%=pageNo+1 %>">下一页</a>&nbsp&nbsp&nbsp //实现功能下一页

<form name="form1" action="ShowArticleFlat.jsp"> //增加用于选择显示第几页的功能
<select name="pageNo" onchange="document.form1.submit()"> //当选项被改变提交时,这个pageNo选项的值被改为第几个选项的值
<%
for(int i=0;i<=totalPages;i++){ //动态的确定有多少个选项
%>
<option value=<%=i %> <%=(pageNo==i)?"selected":"" %>> 第<%=i %>页 //判断pageNo的值是否等于i,等于i就选中这一项,否则不选中。
<%
}
%>
</select>
</form>

<form name="form2" action="ShowArticleFlat.jsp"> //增加利用文本框输入想要选择的页数
<input type="text" size="4" name="pageNo" value=<%=pageNo%> /> //文本框中的值初始为pageNo的值
<input type="submit" value="go" />
</form>

</body>
</html>

 

 mamicode.com,码迷mamicode.com,码迷mamicode.com,码迷

 

 

 

 

 

 

 

 

 

 

简单BBS项目,码迷,mamicode.com

简单BBS项目

标签:des   style   blog   class   java   tar   ext   javascript   width   color   get   

原文地址:http://www.cnblogs.com/mosquito-woo/p/3702874.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!