基于javaweb+mysql的jsp+servlet校园论坛校园bbs(管理员、用户)(java+jsp+servlet+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员:登录、注册、发贴、回复、用户管理、帖子管理等
用户:登录、注册、发贴、回复
用户
管理员
技术框架
CSS JavaScript jQuery JSP Servlet JDBC MySQL
基于javaweb+mysql的JSP+Servlet校园论坛校园BBS(管理员、用户)(java+jsp+servlet+mysql)
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int fid = Integer.parseInt(request.getParameter("fid"));
BbsServiceInf service = new BbsServiceImpl();
//查询所有的回复
ForumEntity forum = service.findReplyList(fid);
request.setAttribute("forum", forum);
request.getRequestDispatcher("page/tourist/replyinfo.jsp").forward(request, response);
}
}
@SuppressWarnings("serial")
public class UPdeleteReplyByIdServlet extends HttpServlet {
public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
String replyid=request.getParameter("rid");
int rid=Integer.parseInt(replyid);
String forumid=request.getParameter("fid");
BbsServiceInf service=new BbsServiceImpl();
service.deleteReplyByRid(rid);
request.setAttribute("forumid", forumid);
request.getRequestDispatcher("UPfindReplyById").forward(request, response);
}
}
}else{
String html = "<div id='confirmdialog' class='easyui-dialog' title='消息确认' style='width:300px;height:160px;padding:10px'";
html = html + "data-options=\"iconCls: 'icon-no',buttons: [{text:'确定',iconCls:'icon-ok',handler:function(){$('#confirmdialog').dialog('close');window.location.href='login.jsp';}}]\"";
html = html + ">用户名或密码有错!</div>";
out.print(html);
}
out.flush();
out.close();
}
}
@SuppressWarnings("serial")
public class RegisterServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
// String user_id = request.getParameter("user_id");
String userid = request.getParameter("user_id");
int user_id=Integer.parseInt(userid);
String user_name = request.getParameter("user_name");
String user_password = request.getParameter("md5Pwd");
String user_sex = request.getParameter("user_sex");
String user_face = request.getParameter("user_face");
String user_phone = request.getParameter("user_phone");
}else{
int pid=Integer.parseInt(user_id);
BbsServiceInf service=new BbsServiceImpl();
List<ForumEntity> personList=new ArrayList<ForumEntity>();
personList=service.personForum(pid);
request.setAttribute("perForumList", personList);
request.getRequestDispatcher("page/user/myforum.jsp").forward(request, response);
}
// PrintWriter out=response.getWriter();
// out.println(user_id);
// out.println(user_id);
}
}
@SuppressWarnings("serial")
public class UPfindReplyByIdServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String forumid=request.getParameter("fid");
if(forumid==null){
String fid=(String)request.getAttribute("forumid");
int f_id=Integer.parseInt(fid);
PrintWriter out= response.getWriter();
out.println(f_id+"ewrew");
BbsServiceInf service = new BbsServiceImpl();
//查询所有的回复
ForumEntity forum = service.findReplyList(f_id);
@SuppressWarnings("serial")
public class ReplyListServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
int fid = Integer.parseInt(request.getParameter("fid"));
BbsServiceInf service = new BbsServiceImpl();
ForumEntity forum = service.findReplyList(fid);
request.setAttribute("forum", forum);
request.getRequestDispatcher("reply.jsp").forward(request, response);
}
}
@SuppressWarnings("serial")
@SuppressWarnings("serial")
public class UserUpdateInfoServlet extends HttpServlet {
public void service (HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
String userid=request.getParameter("user_id");
int user_id=Integer.parseInt(userid);
String user_name=request.getParameter("user_name");
String user_password=request.getParameter("md5Pwd");
String user_sex=request.getParameter("user_sex");
String user_face=request.getParameter("user_face");
String user_phone=request.getParameter("user_phone");
String user_email=request.getParameter("user_email");
String user_from=request.getParameter("user_from");
UserEntity user=new UserEntity();
user.setUser_id(user_id);
user.setUser_name(user_name);
user.setUser_password(user_password);
user.setUser_sex(user_sex);
user.setUser_face(user_face);
user.setUser_phone(user_phone);
user.setUser_email(user_email);
user.setUser_from(user_from);
UserServiceInf service=new UserServiceImpl();
service.updateUser(user);
UserEntity userinfo=service.findUser(user_id);
request.setAttribute("userinfo", userinfo);
request.getRequestDispatcher("page/user/individualinfo.jsp").forward(request,response);
}
}
UserServiceInf service = new UserServiceImpl();
UserEntity user = service.login(user_id, user_password);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<link rel='stylesheet' type='text/css' href='css/easyui.css' />");
out.println("<link rel='stylesheet' type='text/css' href='css/icon.css' />");
if(user!=null){
request.getSession().setAttribute("user", user);
response.sendRedirect("forumList");
}else{
String html = "<div id='confirmdialog' class='easyui-dialog' title='消息确认' style='width:300px;height:160px;padding:10px'";
html = html + "data-options=\"iconCls: 'icon-no',buttons: [{text:'确定',iconCls:'icon-ok',handler:function(){$('#confirmdialog').dialog('close');window.location.href='login.jsp';}}]\"";
html = html + ">用户名或密码有错!</div>";
out.print(html);
}
out.flush();
out.close();
}
}
@SuppressWarnings("serial")
public class RegisterServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String forumid=request.getParameter("fid");
if(forumid==null){
String fid=(String)request.getAttribute("forumid");
int f_id=Integer.parseInt(fid);
PrintWriter out= response.getWriter();
out.println(f_id+"ewrew");
BbsServiceInf service = new BbsServiceImpl();
//查询所有的回复
ForumEntity forum = service.findReplyList(f_id);
request.setAttribute("forum", forum);
request.getRequestDispatcher("page/user/preplyinfo.jsp").forward(request, response);
}else{
int fid = Integer.parseInt(forumid);
PrintWriter out= response.getWriter();
out.println(fid+"ewrew");
BbsServiceInf service = new BbsServiceImpl();
//查询所有的回复
ForumEntity forum = service.findReplyList(fid);
request.setAttribute("forum", forum);
request.getRequestDispatcher("page/user/preplyinfo.jsp").forward(request, response);
}
}
}
@SuppressWarnings("serial")
public class ReplyServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
int fid = Integer.parseInt(request.getParameter("fid"));
int uid = Integer.parseInt(request.getParameter("uid"));
String replyContent = request.getParameter("content");
ForumEntity forum = new ForumEntity();
forum.setFid(fid);
UserEntity user = new UserEntity();
user.setUser_id(uid);
ReplyEntity reply = new ReplyEntity();
reply.setForum(forum);
reply.setUser(user);
reply.setContent(replyContent);
reply.setReplyTime(new java.sql.Timestamp(new java.util.Date().getTime()));
BbsServiceInf service = new BbsServiceImpl();
service.createReply(reply);
response.sendRedirect("replyList?fid="+fid);
}
}
@SuppressWarnings("serial")
@SuppressWarnings("serial")
public class ReplyServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
int fid = Integer.parseInt(request.getParameter("fid"));
int uid = Integer.parseInt(request.getParameter("uid"));
String replyContent = request.getParameter("content");
ForumEntity forum = new ForumEntity();
forum.setFid(fid);
UserEntity user = new UserEntity();
user.setUser_id(uid);
ReplyEntity reply = new ReplyEntity();
reply.setForum(forum);
reply.setUser(user);
reply.setContent(replyContent);
reply.setReplyTime(new java.sql.Timestamp(new java.util.Date().getTime()));
BbsServiceInf service = new BbsServiceImpl();
service.createReply(reply);
response.sendRedirect("replyList?fid="+fid);
}
}
public class UPdeleteReplyByIdServlet extends HttpServlet {
public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
String replyid=request.getParameter("rid");
int rid=Integer.parseInt(replyid);
String forumid=request.getParameter("fid");
BbsServiceInf service=new BbsServiceImpl();
service.deleteReplyByRid(rid);
request.setAttribute("forumid", forumid);
request.getRequestDispatcher("UPfindReplyById").forward(request, response);
}
}
@SuppressWarnings("serial")
public class ReplyListServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
int fid = Integer.parseInt(request.getParameter("fid"));
BbsServiceInf service = new BbsServiceImpl();
ForumEntity forum = service.findReplyList(fid);
request.setAttribute("forum", forum);
request.getRequestDispatcher("reply.jsp").forward(request, response);
}
}
request.setCharacterEncoding("utf-8");
int fid = Integer.parseInt(request.getParameter("fid"));
int uid = Integer.parseInt(request.getParameter("uid"));
String replyContent = request.getParameter("content");
ForumEntity forum = new ForumEntity();
forum.setFid(fid);
UserEntity user = new UserEntity();
user.setUser_id(uid);
ReplyEntity reply = new ReplyEntity();
reply.setForum(forum);
reply.setUser(user);
reply.setContent(replyContent);
reply.setReplyTime(new java.sql.Timestamp(new java.util.Date().getTime()));
BbsServiceInf service = new BbsServiceImpl();
service.createReply(reply);
response.sendRedirect("replyList?fid="+fid);
}
}
@SuppressWarnings("serial")
public class ReleaseServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String title = request.getParameter("title");
String content = request.getParameter("content");
UserEntity user = (UserEntity)request.getSession().getAttribute("user");
ForumEntity forum = new ForumEntity();
@SuppressWarnings("serial")
public class UPfindReplyByIdServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String forumid=request.getParameter("fid");
if(forumid==null){
String fid=(String)request.getAttribute("forumid");
int f_id=Integer.parseInt(fid);
PrintWriter out= response.getWriter();
out.println(f_id+"ewrew");
BbsServiceInf service = new BbsServiceImpl();
//查询所有的回复
ForumEntity forum = service.findReplyList(f_id);
request.setAttribute("forum", forum);
request.getRequestDispatcher("page/user/preplyinfo.jsp").forward(request, response);
}else{
int fid = Integer.parseInt(forumid);
PrintWriter out= response.getWriter();
out.println(fid+"ewrew");
BbsServiceInf service = new BbsServiceImpl();
//查询所有的回复
ForumEntity forum = service.findReplyList(fid);
request.setAttribute("forum", forum);
request.getRequestDispatcher("page/user/preplyinfo.jsp").forward(request, response);
}
}
}
List<ForumEntity> personList=new ArrayList<ForumEntity>();
personList=service.personForum(pid);
request.setAttribute("perForumList", personList);
request.getRequestDispatcher("page/user/myforum.jsp").forward(request, response);
}else{
int pid=Integer.parseInt(user_id);
BbsServiceInf service=new BbsServiceImpl();
List<ForumEntity> personList=new ArrayList<ForumEntity>();
personList=service.personForum(pid);
request.setAttribute("perForumList", personList);
request.getRequestDispatcher("page/user/myforum.jsp").forward(request, response);
}
// PrintWriter out=response.getWriter();
// out.println(user_id);
// out.println(user_id);
}
}
@SuppressWarnings("serial")
public class UPfindReplyByIdServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
@SuppressWarnings("serial")
public class RegisterServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
// String user_id = request.getParameter("user_id");
String userid = request.getParameter("user_id");
int user_id=Integer.parseInt(userid);
String user_name = request.getParameter("user_name");
String user_password = request.getParameter("md5Pwd");
String user_sex = request.getParameter("user_sex");
String user_face = request.getParameter("user_face");
String user_phone = request.getParameter("user_phone");
String user_email = request.getParameter("user_email");
String user_from = request.getParameter("user_from");
UserEntity user = new UserEntity();
user.setUser_id(user_id);
user.setUser_name(user_name);
user.setUser_password(user_password);
user.setUser_sex(user_sex);
user.setUser_face(user_face);
user.setUser_phone(user_phone);
user.setUser_email(user_email);
user.setUser_from(user_from);
UserServiceInf service = new UserServiceImpl();
service.saveUser(user);
//PrintWriter out=response.getWriter();
response.sendRedirect("login.jsp");
//PrintWriter out=response.getWriter();
response.sendRedirect("login.jsp");
//out.print("<a href='login.jsp'>注册成功,请返回登录界面</a>");
}
}
@SuppressWarnings("serial")
public class UserUpdateInfoServlet extends HttpServlet {
public void service (HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
String userid=request.getParameter("user_id");
int user_id=Integer.parseInt(userid);
String user_name=request.getParameter("user_name");
String user_password=request.getParameter("md5Pwd");
String user_sex=request.getParameter("user_sex");
String user_face=request.getParameter("user_face");
String user_phone=request.getParameter("user_phone");
String user_email=request.getParameter("user_email");
String user_from=request.getParameter("user_from");
UserEntity user=new UserEntity();
user.setUser_id(user_id);
user.setUser_name(user_name);
user.setUser_password(user_password);
user.setUser_sex(user_sex);
user.setUser_face(user_face);
user.setUser_phone(user_phone);
user.setUser_email(user_email);
user.setUser_from(user_from);
UserServiceInf service=new UserServiceImpl();
service.updateUser(user);
UserEntity userinfo=service.findUser(user_id);
request.setAttribute("userinfo", userinfo);
request.getRequestDispatcher("page/user/individualinfo.jsp").forward(request,response);
}
}
user.setUser_face(user_face);
user.setUser_phone(user_phone);
user.setUser_email(user_email);
user.setUser_from(user_from);
UserServiceInf service=new UserServiceImpl();
service.updateUser(user);
UserEntity userinfo=service.findUser(user_id);
request.setAttribute("userinfo", userinfo);
request.getRequestDispatcher("page/user/individualinfo.jsp").forward(request,response);
}
}
@SuppressWarnings("serial")
public class UPersonForumListServlet extends HttpServlet {
public void service (HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
String user_id=request.getParameter("uid");
if(user_id==null){
String uid=(String)request.getAttribute("uid");
int pid=Integer.parseInt(uid);
user.setUser_sex(user_sex);
user.setUser_face(user_face);
user.setUser_phone(user_phone);
user.setUser_email(user_email);
user.setUser_from(user_from);
UserServiceInf service = new UserServiceImpl();
service.saveUser(user);
//PrintWriter out=response.getWriter();
response.sendRedirect("login.jsp");
//out.print("<a href='login.jsp'>注册成功,请返回登录界面</a>");
}
}
@SuppressWarnings("serial")
public class UserUpdateInfoServlet extends HttpServlet {
public void service (HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
String userid=request.getParameter("user_id");
int user_id=Integer.parseInt(userid);
String user_name=request.getParameter("user_name");
String user_password=request.getParameter("md5Pwd");
String user_sex=request.getParameter("user_sex");
String user_face=request.getParameter("user_face");
String user_phone=request.getParameter("user_phone");
String user_email=request.getParameter("user_email");
String user_from=request.getParameter("user_from");
UserEntity user=new UserEntity();
user.setUser_id(user_id);
user.setUser_name(user_name);
user.setUser_password(user_password);
user.setUser_sex(user_sex);
user.setUser_face(user_face);
user.setUser_phone(user_phone);
UserServiceInf service=new UserServiceImpl();
service.deleteUser(user_id);
response.sendRedirect("MUserList");
}
}
@SuppressWarnings("serial")
public class TouristFindUserByIdServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String u_id=request.getParameter("uid");
int uid=Integer.parseInt(u_id);
UserServiceInf service=new UserServiceImpl();
UserEntity user=service.findUser(uid);
request.setAttribute("user",user);
request.getRequestDispatcher("page/tourist/userinfo.jsp").forward(request, response);
}
}