package bbs;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.ArrayList;
/**
* 控制器,接受用户的请求,并调用相应的处理方法,返回结果页面
*/
public class TopicServlet
extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
/**
* 判断是哪种操作
* 1,topic_delete:删除贴子
* 2,topic_add:发表新贴
* 3,answer_add:回复贴子
* 4,answer_delete:删除贴子回复
* 5,topic_update:更新贴子
* 6,answer_update:更新贴子回复
* 7,topic_select:获取帖子列表
* 8,topic_view:获取一个帖子以及该帖子的回复
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String method = request.getParameter("method");
//从request对象中获取操作类型,后面代码根据操作类型调用相应的方法进行处理
if (method == null) {
return;
}
else if (method.equalsIgnoreCase("topic_select")) {
topic_select(request, response);
//获取某一讨论区的帖子列表
}
else if (method.equalsIgnoreCase("topic_view")) {
topic_view(request, response);
//获取某一个帖子以及该帖子的回复
}
else if (method.equalsIgnoreCase("topic_delete")) {
topic_delete(request, response);
}
else if (method.equalsIgnoreCase("topic_add")) {
topic_add(request, response);
//创建一个新帖子
}
else if (method.equalsIgnoreCase("answer_add")) {
answer_add(request, response);
//回复一个帖子
}
else if (method.equalsIgnoreCase("answer_delete")) {
answer_delete(request, response);
}
else if (method.equalsIgnoreCase("topic_update")) {
topic_update(request, response);
}
else if (method.equalsIgnoreCase("answer_update")) {
answer_update(request, response);
}
}
/**
* 获取讨论区列表
* 1,获取讨论区编号forum_id
* 2,调用TopicHandle的select方法,获取指定讨论区的帖子列表
* 3,如果出现异常,将异常信息保存到request对象中
* 5,返回topics.jsp页面
*/
private void topic_select(HttpServletRequest request,
HttpServletResponse response) {
boolean isSuccess = false;
//处理成功与否标记
ArrayList array = null;
//用来保存结果集
String forum_id = request.getParameter("forum_id");
//获取讨论区编号forum_id
String start_index = request.getParameter("start_index");
//起始页编号,分页算法中要用到
if (start_index == null) {
start_index = "0";
//起始页编号为空,初始化为“0”,表示第一页
}
Page pageInfo = null;
//分页对象
try {
pageInfo = (Page) request.getAttribute("pageInfo");
//从request中获取分页对象
if (pageInfo == null) {
pageInfo = new Page();
request.setAttribute("pageInfo", pageInfo);
//如果分页对象为空,就创建一个新的分页对象,并保存到request中
}
pageInfo.setIndex(Integer.parseInt(start_index));
//设置分页对象的起始页
pageInfo.setUrl("topicservlet?method=topic_select&forum_id=" +
forum_id);
//设置页面数字对应的URL链接
array = TopicHandle.select(Integer.valueOf(forum_id).intValue(),
pageInfo);
//调用TopicHandle的select方法获取讨论区列表
isSuccess = true;
}
catch (Exception es) {
isSuccess = false;
request.setAttribute("topic_error", es.getMessage());
es.printStackTrace();
array = new ArrayList();
}
if (isSuccess) {
request.removeAttribute("topic_error");
}
request.setAttribute("topics", array);
//将结果集保存到request对象中
String forward = "topics.jsp?forum_id=" + forum_id;
forward(request, response, forward);
}
/**
* 浏览帖子信息
* 1,获得要浏览贴子的讨论区编号forum_id以及贴子号bbs_id
* 2,调用TopicHandle的viewTopic方法,获取编号为bbs_id的贴子以及该贴子的回复
* 3,返回topic_view.jsp页面
*/
private void topic_view(HttpServletRequest request,
HttpServletResponse response) {
String forum_id = request.getParameter("forum_id");
String bbs_id = request.getParameter("bbs_id");
//从request对象中获取贴子的讨论区编号forum_id以及贴子号bbs_id
String start_index = request.getParameter("start_index");
//起始页编号,分页算法中要用到
if (start_index == null) {
start_index = "0";
}
Page pageInfo = null;
ArrayList array = null;
try {
pageInfo = (Page) request.getAttribute("pageInfo");
//从request中获取分页对象
if (pageInfo == null) {
pageInfo = new Page();
request.setAttribute("pageInfo", pageInfo);
//如果分页对象为空,就创建一个新的分页对象,并保存到request中
}
pageInfo.setIndex(Integer.parseInt(start_index));
//设置分页对象的起始页
pageInfo.setUrl("topicservlet?method=topic_view&bbs_id=" + bbs_id +
"&forum_id=" + forum_id);
//设置页面数字对应的URL链接
int id = Integer.parseInt(bbs_id);
array = TopicHandle.viewTopic(id, pageInfo);
//调用业务逻辑层对象,获取帖子以及该帖子的所有回复
}
catch (Exception es) {
es.printStackTrace();
}
request.setAttribute("topic_answer", array);
//将结果保存在request对象中
String forward = "topic_view.jsp?forum_id=" + forum_id + "&bbs_id=" +
bbs_id;
forward(request, response, forward);
}
/**
* 删除贴子以及该贴子的所有回复
* 1,获得要删除的贴子的讨论区编号forum_id以及贴子号bbs_id
* 2,调用TopicHandle的delete方法,删除编号为bbs_id的贴子以及该贴子的回复
* 3,如果出现异常,将异常信息保存到request对象中
* 5,返回forums.jsp页面
*/
private void topic_delete(HttpServletRequest request,
HttpServletResponse response) {
String bbs_id = (String) request.getParameter("bbs_id");
String forum_id = (String) request.getParameter("forum_id");
boolean isSuccess = false;
try {
TopicHandle.delete(Integer.valueOf(bbs_id).intValue());
isSuccess = true;
}
catch (Exception es) {
es.printStackTrace();
isSuccess = false;
request.setAttribute("topic_error", es.getMessage());
}
if (isSuccess) {
request.removeAttribute("topic_error");
}
String forward = "topicservlet?method=topic_select&forum_id=" +
forum_id;
// forward += "&b
没有合适的资源?快使用搜索试试~ 我知道了~
课程设计——讨论区BBS模板jsp
共79个文件
gif:18个
class:15个
java:15个
5星 · 超过95%的资源 需积分: 9 251 下载量 80 浏览量
2008-07-10
19:33:17
上传
评论 2
收藏 478KB RAR 举报
温馨提示
应用MyEclipse编写的讨论区BBS模板案例jsp源代码 课程设计——课程设计——
资源推荐
资源详情
资源评论
收起资源包目录
讨论区BBS模板jsp.rar (79个子文件)
chapter3
.project 1KB
.settings
org.eclipse.core.resources.prefs 88B
.mymetadata 288B
WebRoot
login.jsp 2KB
topic_update.jsp 2KB
success.jsp 541B
WEB-INF
web.xml 1KB
lib
unittest.jar 61KB
mysql-connector-java-3.0.16-ga-bin.jar 231KB
junit.jar 118KB
classes
bbs
TopicServlet.class 8KB
LoginFilter.class 4KB
ForumHandle.class 4KB
User.class 2KB
LoginServlet.class 4KB
TopicHandle.class 6KB
DBHandle.class 2KB
Constant.class 335B
Page.class 3KB
StringUtil.class 1KB
Forum.class 1KB
Topic.class 2KB
ForumServlet.class 5KB
UserHandle.class 4KB
EncodingFilter.class 2KB
index.jsp 549B
forum_update.jsp 2KB
META-INF
MANIFEST.MF 39B
user_add.jsp 3KB
include
check.js 563B
default.css 9KB
style.css 1KB
forum_view.jsp 856B
topic_add.jsp 2KB
topics.jsp 3KB
forum_add.jsp 2KB
user_update.jsp 3KB
images
moon.gif 22KB
return.gif 152B
smill.gif 491B
topics.gif 364B
new.gif 152B
forum.gif 31KB
notuse
istop.gif 185B
post.gif 983B
fabiao.gif 812B
ztop.gif 596B
Thumbs.db 14KB
up.gif 152B
topic.gif 571B
postnew.gif 2KB
folder.gif 571B
newreply.gif 900B
votenew.gif 980B
Thumbs.db 8KB
hottopic.gif 367B
zayan.gif 1KB
forums.jsp 2KB
topic_view.jsp 4KB
error_info.jsp 300B
database
dbscript.sql 2KB
.myeclipse
src
bbs
TopicServlet.java 20KB
EncodingFilter.java 2KB
LoginServlet.java 5KB
ForumServlet.java 12KB
ForumHandle.java 7KB
Constant.java 95B
LoginFilter.java 4KB
User.java 2KB
StringUtil.java 1KB
TopicHandle.java 9KB
Forum.java 966B
UserHandle.java 6KB
Page.java 5KB
Topic.java 2KB
DBHandle.java 2KB
.classpath 576B
doc
系统移植说明.doc 26KB
bbs.xml 1KB
共 79 条
- 1
资源评论
- woshtiongtong2014-06-29郊果挺好的,代码不够简洁。
- w3102288902012-10-24效果挺好的 ,注释不是很清楚
- liuyuheng02082012-04-15效果不错 但是代码 不够简洁 还有 最好别叫模板 除了数据库 基本功能已经实现
java_flying_2007
- 粉丝: 7
- 资源: 132
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功