package cn.cultivator.bbs.servlet;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;
import cn.cultivator.bbs.domain.Topic;
import cn.cultivator.bbs.domain.Type;
import cn.cultivator.bbs.domain.User;
import cn.cultivator.bbs.exception.PasswordErrorException;
import cn.cultivator.bbs.service.BbsService;
public class BbsServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String method = request.getParameter("method");
if("findAllType".equals(method)){
this.listAllType(request, response);
}else if("toLogin".equals(method)){
request.getRequestDispatcher("jsp/login.jsp").forward(request, response);
}else if("Login".equals(method)){
this.Userlogin(request, response);
}else if ("toRegister".equals(method)) {
request.getRequestDispatcher("jsp/register.jsp").forward(request, response);
}else if ("register".equals(method)) {
this.UserRegister(request, response);
}else if("exit".equals(method)){
this.exit(request, response);
}else if("listTopic".equals(method)){
this.ListAllTopic(request, response);
}else if("toAddTopic".equals(method)){
request.getRequestDispatcher("jsp/addTopic.jsp").forward(request, response);
}else if("addTopic".equals(method)){
this.addTopic(request, response);
}
}
private void listAllType(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
BbsService bbsService = new BbsService();
List<Type> typeList = bbsService.listAllType();
request.setAttribute("typeList",typeList);
request.getRequestDispatcher("jsp/listAllType.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("message", "查询版块出错");
request.getRequestDispatcher("jsp/message.jsp").forward(request, response);
}
}
private void Userlogin(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
User user = new User();
Enumeration<String> enums = request.getParameterNames();
while(enums.hasMoreElements()){
String name = enums.nextElement();
String[] values = request.getParameterValues(name);
BeanUtils.setProperty(user, name, values);
}
BbsService bbsService = new BbsService();
User u = bbsService.login(user);
/*System.out.println(request.getContentType());*/
if(u!=null){
request.getSession().setAttribute("user", user);
response.sendRedirect(request.getContextPath()+"/welcome.jsp");
}else {
throw new PasswordErrorException();
}
} catch (PasswordErrorException e) {
e.printStackTrace();
request.setAttribute("message", "You hava a fault");
request.getRequestDispatcher("jsp/message.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("message", "登录失败");
request.getRequestDispatcher("jsp/message.jsp").forward(request, response);
}
}
private void UserRegister(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
User user = new User();
Enumeration<String> enumerations = request.getParameterNames();
while (enumerations.hasMoreElements()) {
String name = enumerations.nextElement();
Object[] value = request.getParameterValues(name);
BeanUtils.setProperty(user, name, value);
}
BbsService bbsService = new BbsService();
bbsService.register(user);
request.setAttribute("message", "register succeed!");
request.getRequestDispatcher("/jsp/message.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
private void exit(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
session.invalidate();
response.sendRedirect(request.getContextPath()+"/welcome.jsp");
}
private void ListAllTopic(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
Integer typeId = Integer.valueOf(request.getParameter("typeId"));
String tokenId1 = request.getParameter("tokenId");
String tokenId2 = (String) request.getSession().getAttribute("token");
// System.out.println(tokenId1);
// System.out.println(tokenId2);
BbsService bbsService = new BbsService();
if(tokenId1!=null&&tokenId2!=null&&tokenId1.equals(tokenId2)){
bbsService.updateClickNum(typeId);
request.getSession().removeAttribute("tokenId2");
}
List<Topic> topicList = bbsService.listAllTopic(typeId);
request.setAttribute("topicList", topicList);
request.getRequestDispatcher("jsp/listAllTopic.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
private void addTopic(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
Topic topic = new Topic();
Enumeration<String> enums = request.getParameterNames();
while(enums.hasMoreElements()){
String name = enums.nextElement();
String[] value = request.getParameterValues(name);
BeanUtils.setProperty(topic, name, value);
}
BbsService bbsService = new BbsService();
bbsService.addTopic(topic);
request.setAttribute("message", "success to add");
request.getRequestDispatcher("jsp/message.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
request.setAttribute("message", "fail to add");
request.getRequestDispatcher("jsp/message.jsp").forward(request, response);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于jsp、javaBean、servlet的论坛系统.zip
共91个文件
class:26个
java:22个
gif:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 58 浏览量
2023-06-28
16:43:44
上传
评论
收藏 2.19MB ZIP 举报
温馨提示
本资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。有任何问题也可以随时私信博主,博主会第一时间给您解答!!! 本资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。有任何问题也可以随时私信博主,博主会第一时间给您解答!!! 本资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。有任何问题也可以随时私信博主,博主会第一时间给您解答!!!
资源推荐
资源详情
资源评论
收起资源包目录
基于jsp、javaBean、servlet的论坛系统.zip (91个子文件)
content
.classpath 948B
.settings
org.eclipse.jdt.core.prefs 323B
.mymetadata 284B
src
bbs.sql 6KB
cn
cultivator
bbs
servlet
BbsServlet.java 6KB
dao
UserDao.java 1KB
AddressDao.java 568B
TypeDao.java 3KB
service
BbsService.java 2KB
FormValidate.java 2KB
filter
EncodingFilter.java 2KB
CopyrightFilter.java 2KB
FilterEncoding.java 4KB
exception
PasswordErrorException.java 96B
UserNameExistException.java 96B
listener
OnlineListener.java 952B
AddressListener.java 985B
util
WebUtil.java 976B
JdbcUtil.java 274B
domain
Type.java 1KB
Flow.java 490B
Admin.java 301B
Reply.java 901B
Topic.java 1013B
Address.java 443B
User.java 757B
c3p0-config.xml 326B
WebRoot
ads
javamail.gif 10KB
jsf.jpg 11KB
ejb.jpg 3KB
oracle.gif 9KB
spring.gif 8KB
j2ee.jpg 11KB
javaweb1.gif 10KB
javascript.gif 9KB
java.gif 9KB
javaweb2.gif 10KB
WEB-INF
classes
bbs.sql 6KB
cn
cultivator
bbs
servlet
BbsServlet.class 6KB
dao
UserDao.class 2KB
TypeDao.class 4KB
AddressDao.class 1KB
service
FormValidate.class 2KB
BbsService.class 4KB
filter
EncodingFilter$MyRequest.class 1KB
EncodingFilter$MyRequest$1.class 2KB
EncodingFilter.class 2KB
CopyrightFilter.class 2KB
MyResponse.class 1KB
MyCharacterEncodingRequest.class 1KB
FilterEncoding.class 2KB
exception
UserNameExistException.class 350B
PasswordErrorException.class 350B
listener
AddressListener.class 2KB
OnlineListener.class 1KB
util
JdbcUtil.class 610B
WebUtil.class 2KB
domain
User.class 1KB
Address.class 981B
Reply.class 2KB
Topic.class 2KB
Flow.class 978B
Admin.class 787B
Type.class 2KB
c3p0-config.xml 326B
lib
c3p0-0.9.1.2.jar 596KB
commons-dbutils-1.4.jar 48KB
Standard.jar 384KB
Jstl.jar 20KB
mysql-connector-java-5.1.7-bin.jar 693KB
commons-beanutils-1.8.0.jar 226KB
commons-logging.jar 59KB
web.xml 2KB
welcome.jsp 832B
images
house.jpg 13KB
buttom.gif 652B
computer.jpg 21KB
game.jpg 130KB
car.jpg 41KB
phone.jpg 24KB
flag.gif 994B
META-INF
MANIFEST.MF 36B
jsp
addTopic.jsp 2KB
foot.jsp 2KB
message.jsp 802B
head.jsp 2KB
register.jsp 2KB
listAllType.jsp 2KB
listAllTopic.jsp 2KB
login.jsp 1KB
.project 1KB
system
共 91 条
- 1
资源评论
白话机器学习
- 粉丝: 1w+
- 资源: 7670
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (178548844)zotero文献阅读以及主题和翻译插件
- (179839044)64402-MySQL数据库基础实例教程(第3版)(微课版)-源代码(含例题、案例、实训、实战四个项目).zip.zip
- 基于微信小程序的户外旅游小程序.zip
- 双摇臂履带底盘sw16可编辑全套技术开发资料100%好用.zip
- 国外某地气温数据(extend:2011-2016年).zip
- (18695238)libsvm文档
- 数据分析-51-小红书达人画像
- 基于微信小程序的华云智慧园区(包括数据库,源码).zip
- 步进电机驱动 C#上位机和STM32下位机源程序 步数方向控制
- 船上用品检测12-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- 非常好用 的,局域网,文件共享,文档管理 工作,方便检索文件 ,支持HTTP服务
- 手机组装自动镭焊机step全套技术开发资料100%好用.zip
- java项目,毕业设计-基于协同过滤算法商品推荐系统
- 大三-一个简单的安卓移动开发课程设计Android Studio
- 数据分析-53-「猛男的童年回忆」三大类型玩具在京东平台的销售分析
- C# TouchSocket的基础使用,连接,发送,接收WPF
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功