基于JSP论坛课程设计报告-.doc
JSP课程设计报告BBS论坛设计一、 BBS论坛BBS的英文全称是Bulletin Board System,译为“电子公告板”。BBS最早是用来公布股市价格等类信息的,一直到互联网与个人计算机普及后广泛流行于网络。目前,通过BBS系统开发出各种论坛、网上社区、交友中心等信息平台。二、 BBS系统角色本系统实现BBS论坛的浏览、发贴、注册等功能。系统的角色分为:1、 普通用户(游客)浏览信息(主贴及加回帖)、用户注册2、 注册用户用户登录、发表主贴、对相关的主贴发表回帖、个人信息维护3、 版主对所属版块信息的维护,对不合适的主贴及回帖维护4、 系统管理员对版块进行管理,对用户进行管理三、 设计基本思路(修改相应的名称与本人项目对应,也可自己设计类似的图)BBS.jsp论坛主页面topiclis.jsp显主题帖、发帖页面发帖replylist.jsp显主题帖、发帖页面发帖GetTopicServlet获取相应板块主帖GetReplyServlet获取相应板块主帖AddTopicServlet获取相应板块主帖AddReplyServlet获取相应板块主帖发主题帖查看回帖发回帖DelReplyServlet删除回帖删除回帖DelTopicServlet删除主帖删除主题帖四、 BBS详细设计分析(给出各页面的运行效果截图、相关的Servlet代码,Servlet关键加注释)1:背景加的是浮动框架代码:<html><head><title>未标题-2</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><!- Save for Web Slices (未标题-2) -><table id="_01" width="1247" height="567" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="3"><img src="images/jing_01.jpg" width="1247" height="50" alt=""></td></tr><tr><td width="90"><img src="images/jing_02.jpg" width="63" height="465" alt=""></td> <td width="1091"><iframe name="left" width="100%" height="80%" scrolling="yes" src="login.jsp" frameborder="0"></iframe></td><td width="66"><img src="images/jing_04.jpg" width="63" height="465" alt=""></td></tr><tr><td colspan="3"><img src="images/jing_05.jpg" width="1247" height="52" alt=""></td></tr></table><!- End Save for Web Slices -></body></html>1、 系统主页面BBS.jsp运行截图:() 相关代码:导入标签:<% taglib uri=" prefix="c" %><body> <p><br> <img src="images/logo.jpg" width="290" height="70"> <% String uname=(String)session.getAttribute("uname"); %> <% if(uname=null) %> <div>你尚未登录 | <a href="login.jsp">登录</a> | 注册</div> <% else %> <div>当前用户:<%=uname %></div> <p><% %> <p><a href="GetTopicServlet?currentpage=1&boardid=$boardid">首页</a> </p> <table width="928" height="83" border="1" align="left" cellpadding="0" cellspacing="0"> <%ArrayList<Board> bdata=BoardDao.getAllBoard(); for(int i=0;i<bdata.size();i+)Board tem=bdata.get(i);%> <tr> <th width="134" bgcolor="#00BC9A" scope="col"><div align="center"><img src="images/icon3.gif" width="18" height="16"></div></th> <th width="632" bgcolor="#00BC9A" scope="col"><div align="center"><a href="GetTopicServlet?boardid=<%=tem.getBid() %>"><%=tem.getBname() %></a></div></th> <th width="105" bgcolor="#00BC9A" scope="col"><div align="center">主贴数:<%=tem.getTopicnum() %></div></th> <th width="47" bgcolor="#00BC9A" scope="col"><div align="center"></div></th> </tr> <tr> <td bgcolor="#00BC9A"><div align="center"></div></td> <td><div align="center">版主: <% ArrayList<User> udata=tem.getBuserdata(); for(int j=0;j<udata.size();j+) out.print(udata.get(j).getUname()+" "); %> </div></td> <td><div align="center"></div></td> <td><div align="center"></div></td> </tr><% %> </table> <p> </p> </body></html>GetTopicServlet:/1 获取版块的idString boardid=request.getParameter("boardid");System.out.print("bid="+boardid);String curnum=request.getParameter("currentpage");if(curnum=null)curnum="1"/2 调用相关的类查询相关的信息GetPage mypage=new GetPage();DBConnect mydb=new DBConnect();String sql="select * from topic where boardid="+boardid;mypage.setDb(mydb);mypage.setKeyFielsName("topicid");mypage.setP_curpage(Integer.parseInt(curnum);mypage.setPageSize(3);mypage.setSql(sql);ArrayList<Topic> tdata=new ArrayList<Topic>();ResultSet re=null;try re=mypage.getPage();while(re.next()Topic tem=new Topic();tem.setTopicid(re.getString(1);tem.setTitle(re.getString(2);tem.setTdata(re.getString(4);tem.setReplynum(ReplayDao.getReplayByTopicId(tem.getTopicid()+"");String userid=re.getString(5);tem.setTopicuser(UserDao.getUserInfoByUserId(userid);tdata.add(tem);catch (Exception e) e.printStackTrace();/判断是否为版主HttpSession session=request.getSession();String u=(String)session.getAttribute("uid");System.out.print("u="+u+"aa");boolean flag=false;if(u!=null)/u不为空说明登陆用户,判断是否为版主flag=MasterDao.checkMaster(u, boardid);/3 将查询结果送到信息显示request.setAttribute("flag", flag);System.out.print("dd="+tdata.size();request.setAttribute("ttdata", tdata);request.setAttribute("boardid", boardid);request.setAttribute("curpage", mypage.getP_curpage();request.setAttribute("totalpage", mypage.getTotalPage();request.getRequestDispatcher("topiclist.jsp").forward(request, response); 2、 主题帖显示及发帖页面topiclist.jsp相关代码: 导入标签:<% taglib uri=" prefix="c" %><body> <img src="images/logo.jpg" width="290" height="70"> <% String uname=(String)session.getAttribute("uname"); %> <% if(uname=null) %> <div>你尚未登录 | <a href="login.jsp">登录</a> | 注册</div> <% else %> <div>当前用户:<%=uname %></div> <p><% %> <p>首页</p> <table width="1018" height="133" border="1" cellpadding="0" cellspacing="0"> <tr> <th width="92" bgcolor="#00BC9A" scope="col"><div align="center">*</div></th> <th width="521" bgcolor="#00BC9A" scope="col"><div align="center">主帖标题</div></th> <th width="124" bgcolor="#00BC9A" scope="col"><div align="center">发帖人</div></th> <th width="67" bgcolor="#00BC9A" scope="col"><div align="center">回帖数</div></th> <th width="202" bgcolor="#00BC9A" scope="col"><div align="center">发帖时间</div></th> </tr> <c:forEach items="$requestScope.ttdata" var="tem"> <tr> <td align="center"> <c:if test="$flag='true'"> <a href="delTopicservlet?topicid=$tem.topicid&&boardid=$param.boardid ">删除</a> </c:if> <c:if test="$flag!='true'"> <img src="images/headimage4.JPG" width="17" height="17"> </c:if></td> <td><a href="NeiRong?topicid=$tem.topicid">$tem.title </a></td> <td align="center">$tem.topicuser.uname</td> <td align="center">$tem.replynum </td> <td align="center">$tem.tdata </td> </tr> </c:forEach> </table> <p align="center">共$totalpage 页 当前第$curpage 页 <a href="GetTopicServlet?currentpage=1&boardid=$boardid">首页</a> <a href="GetTopicServlet?currentpage=$requestScope.curpage-1&boardid=$boardid">上一页</a> <a href="GetTopicServlet?currentpage=$requestScope.curpage+1&boardid=$boardid">下一页</a> <a href="GetTopicServlet?currentpage=$totalpage&boardid=$boardid"> 尾页</a></p></body></html>delTopicservlet:String topicid=request.getParameter("topicid");String boardid=request.getParameter("boardid");System.out.print(topicid+boardid);int n=TopicDao.delTopicByTopicId(topicid);if(n>0)request.getRequestDispatcher("GetTopicServlet?boardid="+boardid).forward(request, response);elseSystem.out.print("删除失败");3、 回帖查看及发回帖页面replylist.jsp相关代码:导入标签:<% taglib uri=" prefix="c" %> </head> <script language="javascript"> function check() var a=document.form1.flag.value;if(a="")alert("要发贴,请先登录");return false;var b=document.form1.contentinfo.value;if(content="")alert("请输入主帖的标题");return false;return true; </script> <body> <table width="1039" height="167" border="1" cellpadding="0" cellspacing="0"> <tr> <th width="257" bgcolor="#00bc9a" scope="col"><div align="center">发帖人:$topicInfo.topicuser </div></th> <th width="501" bgcolor="#00BC9A" scope="col">主帖标题:$topicinfo.title </th> <th width="148" bgcolor="#00BC9A" scope="col">发帖时间:$topicinfo.tdata </th> <th width="123" bgcolor="#00BC9A" scope="col"> </th> </tr> <tr> <td height="48"><p align="center" class="STYLE1 STYLE1"><img src="images/16.gif" width="14" height="14"></p> <p align="center" class="STYLE1 STYLE1">$topicinfo.topicuser.uname </p></td> <td colspan="3"align="left" valign="top"><p class="STYLE1 STYLE1">内容:</p> <p class="STYLE1 STYLE1">$topicinfo.tcontent </p></td> </tr> <c:forEach items="$rdata" var="tem" varStatus="i"> <tr> <td height="28" bgcolor="#00BC9A" class="a"><div align="center" class="STYLE1">回帖人</div></td> <td bgcolor="#00BC9A" class="a">回帖时间:$tem.creatdate </td> <td bgcolor="#00BC9A" class="a">楼层: <c:if test="$i.count=1 ">沙发</c:if> <c:if test="$i.count!=1 ">$i.count </c:if></td> <td bgcolor="#00BC9A" class="a"><a href="delReplyservlet?replyid=$tem.replyid&&topicid=$tem.topicid">删除</a></td> </tr> <tr> <td height="48"><div align="center" class="STYLE1"> <p><img src="images/6.gif" width="14" height="14"></p> <p>$tem.replyuser.uname</p> </div></td> <td colspan="3" align="left" valign="top"><span class="STYLE1"> <c:if test="$tem.rstatus=0"> 该帖子已被删除</c:if> <c:if test="$tem.rstatus=1"> $tem.contentinfo </c:if> </span></td> </tr> </c:forEach> </table> <form name="form1" method="post" action="addreplyservlet"> <table width="315" height="125" border="1" align="center" cellpadding="0" cellspacing="0"> <tr> <th colspan="2" bgcolor="#00BC9A" scope="col">跟帖(提示:请登录)</th> </tr> <tr> <td bgcolor="#00BC9A">内容</td> <td><label> <textarea name="contentinfo" cols="30" rows="8"></textarea> <input type="hidden" name="flag" value="$sessionScope.userinfo"> <input type="hidden" name="topicid" value="$param.topicid"> </label></td> </tr> <tr> <td height="23" colspan="2" align="center" bgcolor="#00BC9A"><label> <input type="submit" name="Submit" value="提交"> <input type="reset" name="Submit2" value="重置"> </label></td> </tr> </table> </form> </body> addreplyservlet:request.setCharacterEncoding("gb2312");String content=request.getParameter("contentinfo");String topicid=request.getParameter("topicid");System.out.print(content+"|"+topicid+"|");HttpSession session=request.getSession();String userid=(String)session.getAttribute("uid");int n=ReplayDao.addReply(content, topicid, userid);/3转向if(n>0)/合法用户 response.sendRedirect("NeiRong?topicid="+topicid);else/非法用户response.sendRedirect("添加失败!");回帖:<% taglib uri=" prefix="c" %> </head> <script language="javascript"> function check() var a=document.form1.flag.value;if(a="")alert("要发贴,请先登录");return false;var b=document.form1.contentinfo.value;if(content="")alert("请输入主帖的标题");return false;return true; </script> <body> <table width="1039" height="167" border="1" cellpadding="0" cellspacing="0"> <tr> <th width="257" bgcolor="#00bc9a" scope="col"><div align="center">发帖人:$topicInfo.topicuser </div></th> <th width="501" bgcolor="#00BC9A" scope="col">主帖标题:$topicinfo.title </th> <th width="148" bgcolor="#00BC9A" scope="col">发帖时间:$topicinfo.tdata </th> <th width="123" bgcolor="#00BC9A" scope="col"> </th> </tr> <tr> <td height="48"><p align="center" class="STYLE1 STYLE1"><img src="images/16.gif" width="14" height="14"></p> <p align="center" class="STYLE1 STYLE1">$topicinfo.topicuser.uname </p></td> <td colspan="3"align="left" valign="top"><p class="STYLE1 STYLE1">内容:</p> <p class="STYLE1 STYLE1">$topicinfo.tcontent </p></td> </tr> <c:forEach items="$rdata" var="tem" varStatus="i"> <tr> <td height="28" bgcolor="#00BC9A" class="a"><div align="center" class="STYLE1">回帖人</div></td> <td bgcolor="#00BC9A" class="a">回帖时间:$tem.creatdate </td> <td bgcolor="#00BC9A" class="a">楼层: <c:if test="$i.count=1 ">沙发</c:if> <c:if test="$i.count!=1 ">$i.count </c:if></td> <td bgcolor="#00BC9A" class="a"><a href="delReplyservlet?replyid=$tem.replyid&&topicid=$tem.topicid">删除</a></td> </tr> <tr> <td height="48"><div align="center" class="STYLE1"> <p><img src="images/6.gif" width="14" height="14"></p> <p>$tem.replyuser.uname</p> </div></td> <td colspan="3" align="left" valign="top"><span class="STYLE1"> <c:if test="$tem.rstatus=0"> 该帖子已被删除</c:if> <c:if test="$tem.rstatus=1"> $tem.contentinfo </c:if> </span></td> </tr> </c:forEach> </table> <form name="form1" method="post" action="addreplyservlet"> <table width="315" height="125" border="1" align="center" cellpadding="0" cellspacing="0"> <tr> <th colspan="2" bgcolor="#00BC9A" scope="col">跟帖(提示:请登录)</th> </tr> <tr> <td bgcolor="#00BC9A">内容</td> <td><label> <textarea name="contentinfo" cols="30" rows="8"></textarea> <input type="hidden" name="flag" value="$sessionScope.userinfo"> <input type="hidden" name="topicid" value="$param.topicid"> </label></td> </tr> <tr> <td height="23" colspan="2" align="center" bgcolor="#00BC9A"><label> <input type="submit" name="Submit" value="提交"> <input type="reset" name="Submit2" value="重置"> </label></td> </tr> </table> </form> </body> addreplyservletrequest.setCharacterEncoding("gb2312");String content=request.getParameter("contentinfo");String topicid=request.getParameter("topicid");System.out.print(content+"|"+topicid+"|");HttpSession session=request.getSession();String userid=(String)session.getAttribute("uid");int n=ReplayDao.addReply(content, topicid, userid);/3转向if(n>0)/合法用户 response.sendRedirect("NeiRong?topicid="+topicid);else/非法用户response.sendRedirect("添加失败!");4、 用户登录5、 <body> <div align="center"><img src="images/logo.jpg" width="290" height="70"><br> <% String uname=(String)session.getAttribute("uname"); %> <% if(uname=null) %> </div> <div> <div align="center">你尚未登录 | <a href="login.jsp">登录</a> | 注册</div> </div> <div align="center"> <% else %> </div> <di