JSP课设:论坛管理系统(附源码+调试)

JSP论坛管理系统

(1)注册模块:游客点击注册模块,输入账号,密码,昵称进行注册。
(2)登录模块:用户注册之后,输入账号和密码即可登录。
(3)我要发贴:点击发帖,进入我要发帖模块,用户输入标题和内容,并选择发布浏览器即可发帖。
(4)我的帖子:用户可以查看自己发布的帖子标题,发帖时间,浏览次数,并可以对帖子进行删除操作。
(5)评论帖子:用户可以在帖子中心浏览帖子,点进去之后,可以对帖子内容进行评论。
(6)个人资料:用户可以查看个人资料,修改个人资料,密码和头像等信息。

代码链接:https://pan.baidu.com/s/15EBudlmILzAwuDFuXT9KTQ
提取码:hd7b

系统截图
1、系统首页
JSP课设:论坛管理系统(附源码+调试)_第1张图片
2、注册页面
JSP课设:论坛管理系统(附源码+调试)_第2张图片
3、登录页面
JSP课设:论坛管理系统(附源码+调试)_第3张图片
4、帖子中心
JSP课设:论坛管理系统(附源码+调试)_第4张图片
5、我要发帖
JSP课设:论坛管理系统(附源码+调试)_第5张图片
6、发表评论
JSP课设:论坛管理系统(附源码+调试)_第6张图片
7、个人资料
JSP课设:论坛管理系统(附源码+调试)_第7张图片

部分核心代码
1、数据库连接

package cn.cqut.edu.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class BaseDao {
	// 数据URL
	private static final String url = "jdbc:mysql://localhost:3306/forum?Unicode=true&characterEncoding=UTF-8";

	// 用户名
	private static final String username = "root";

	// 密码
	private static final String password = "123456";

	// 数据库驱动
	private static final String jdbcDriver = "com.mysql.jdbc.Driver";

	// 调用 ParameterMetaData.getParameterType(i + 1) 是否会抛出异常
	protected boolean pmdKnownBroken = false;

	public BaseDao() {

	}

	public BaseDao(boolean pmdKnownBroken) {
		this.pmdKnownBroken = pmdKnownBroken;
	}

	public Connection getConnetion() {

		Connection conn = null;
		try {
			Class.forName(jdbcDriver);
			conn = DriverManager.getConnection(url, username, password);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return conn;
	}

	/** 根据给定的参数 执行Sql 查询语句,把结果集合放在一个 List> 里面 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> executeQuery(String sql, Object[] params) {
		return (List<Map<String, Object>>) this.excuteQuery(sql, params,
				new ListMapHander());
	}

	/** 查村传进来的sql语句, 按照所需要的接口的方法处理结果集,返回所需要的结果集的格式 */
	
	public Object excuteQuery(String sql, Object[] params, ResultSetHander rsh) {
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Connection con = this.getConnetion();
		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
		try {
			stmt = con.prepareStatement(sql);

			System.out.println("SQL:" + sql + "; Parameters:"
					+ Arrays.deepToString(params));

			// 填充Statement的参数
			fillStatement(stmt, params);
			// 执行查询
			rs = stmt.executeQuery();
			Object obj = rsh.doHander(rs);
			return obj;

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			// 关闭数据库连接
			close(con, stmt, rs);
		}
		return resultList;
	}

	/**
	 * 更新操作  返回值1:成功
	 */
	public int executeUpdate(String sql, Object[] params) {
		PreparedStatement stmt = null;
		Connection con = this.getConnetion();

		int rs = 0;
		try {
			con.setAutoCommit(false);
			// 创建PreparedStatement对象
			stmt = con.prepareStatement(sql);
			// 填充Statement的参数
			fillStatement(stmt, params);
			System.out.println("SQL:" + sql + "; Parameters:"
					+ Arrays.deepToString(params));
			// 执行查询
			rs = stmt.executeUpdate();
			// 提交事务
			con.commit();
			// 把事务设置为原来的状态
			con.setAutoCommit(true);
		} catch (SQLException e) {
			// 在捕获到异常的时候事务回滚
			try {
				con.rollback();
				if (!con.getAutoCommit()) {
					con.setAutoCommit(true);
				}
			} catch (SQLException e1) {
				e.printStackTrace();
				System.out.println("update database error");
			}
			System.out.println("update database error");
		} finally {
			// 关闭数据库连接
			close(con, stmt, null);
		}
		return rs;
	}

	/**
	 * @Title: fillStatement
	 * @Description: 填充SQL参数
	 * @param stmt
	 * @param params
	 * @throws SQLException
	 * @return void
	 */
	private void fillStatement(PreparedStatement stmt, Object[] params)
			throws SQLException {

		/**
		 * 检测参数的个数是否合法,但是有的数据库驱动不支持 stmt.getParameterMetaData()这个方法。
		 * 因此我们有一个一个pmdKnownBroken 变量来标识当前数据驱动是否支持该方法的调用。
		 */
		ParameterMetaData pmd = null;
		if (!pmdKnownBroken) {
			pmd = stmt.getParameterMetaData();
			int stmtCount = pmd.getParameterCount();
			int paramsCount = params == null ? 0 : params.length;

			if (stmtCount != paramsCount) {
				System.out.println("stmtCount:" + stmtCount + ",paramsCount:"
						+ paramsCount);
				throw new SQLException("Wrong number of parameters: expected "
						+ stmtCount + ", was given " + paramsCount);
			}
		}

		// 如果 参数 为 null 直接返回
		if (params == null) {
			return;
		}

		for (int i = 0; i < params.length; i++) {
			if (params[i] != null) {
				stmt.setObject(i + 1, params[i]);
			} else {
				int sqlType = Types.VARCHAR;
				if (!pmdKnownBroken) {
					try {
						sqlType = pmd.getParameterType(i + 1);
					} catch (SQLException e) {
						pmdKnownBroken = true;
					}
				}
				stmt.setNull(i + 1, sqlType);
			}
		}
	}

	/**
	 * 关闭数据库连接
	 */
	private void close(Connection con, Statement stmt, ResultSet rs) {

		if (rs != null) {
			try {
				rs.close();
			} catch (Exception e) {
			} finally {
				if (stmt != null) {
					try {
						stmt.close();
					} catch (SQLException e) {
						e.printStackTrace();
					} finally {
						if (con != null) {
							try {
								con.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
					}
				}
			}
		}
	}
}

2、前端首页代码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%
	response.setContentType("text/html;charset=UTF-8");
	request.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>Bwly论坛</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery-1.11.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
	window.onload = function() {

		var name1 = document.getElementById("userName");
		//用户名
		var name2 = document.getElementById("regAccount");
		//昵称
		var password = document.getElementById("regPwd1");
		//密码
		var password2 = document.getElementById("regPwd2");
		//确认密码

		/*用户名验证*/
		name1.onfocus = function() {
			name1_msg.innerHTML = "1-4个汉字或字母";
		};

		name1.onkeyup = function() {

		};

		name1.onblur = function() {
			//含有非法字符
			var re = /[^\w\u4e00-\u9fa5]/g;
			if (re.test(this.value)) {
				name1_msg.innerHTML = "ps:含有非法字符!";
			}
			//不能为空
			else if (this.value == "") {
				name1_msg.innerHTML = "ps:用户名不能为空!";
			}
			//长度超过10个汉字或字母
			else if (this.value.length > 4) {
				name1_msg.innerHTML = "ps:长度超过10个汉字或字母!";
			}
			//验证通过
			else {
				name1_msg.innerHTML = '';
			}
		};

		/*用户昵称验证*/
		name2.onfocus = function() {
			name2_msg.innerHTML = "ps:2-8个汉字或字母";
		};

		name2.onkeyup = function() {

		};

		name2.onblur = function() {
			//含有非法字符
			var re = /[^\w\u4e00-\u9fa5]/g;
			if (re.test(this.value)) {
				name2_msg.innerHTML = "ps:含有非法字符!";
			}
			//不能为空
			else if (this.value == "") {
				name2_msg.innerHTML = "ps:用户昵称不能为空!";
			}
			//长度超过10个汉字或字母
			else if (this.value.length > 8) {
				name2_msg.innerHTML = "ps:长度超过8个汉字或字母!";
			}
			//长度少于2个汉字或字母
			else if (this.value.length < 2) {
				name2_msg.innerHTML = "ps:长度少于2个汉字或字母!";
			}
			//用户名与用户昵称不能相同
			else if (this.value == name1.value) {
				name2_msg.innerHTML = "ps:用户名与用户昵称不能相同!";
			}
			//验证通过
			else {
				name2_msg.innerHTML = '';
			}
		};

		/*密码验证*/
		password.onfocus = function() {
			password1_msg.innerHTML = "ps:6-10个数字或字母";
		};

		password.onkeyup = function() {

		};

		password.onblur = function() {
			//含有非法字符
			var re = /[^\w\u4e00-\u9fa5]/g;
			if (re.test(this.value)) {
				password1_msg.innerHTML = "ps:含有非法字符!";
			}
			//不能为空
			else if (this.value == "") {
				password1_msg.innerHTML = "ps:密码不能为空!";
			}
			//长度超过10个汉字或字母
			else if (this.value.length > 10) {
				password1_msg.innerHTML = "ps:长度超过10!";
			}
			//长度少于2个汉字或字母
			else if (this.value.length < 6) {
				password1_msg.innerHTML = "ps:长度少于6!";
			}
			//验证通过
			else {
				password1_msg.innerHTML = '';
			}
		};

		/*密码再次验证*/
		password2.onfocus = function() {
			password2_msg.innerHTML = "请再次输入密码";
		};

		password2.onkeyup = function() {

		};

		password2.onblur = function() {
			//var re = /[^\w\u4e00-\u9fa5]/g;
			//不能为空
			if (this.value == "") {
				password2_msg.innerHTML = "确认密码不能为空!";
			}
			//验证通过
			else if (this.value != password.value) {
				password2_msg.innerHTML = "密码输入不一样!";
			}
			//验证通过
			else {
				password2_msg.innerHTML = '';
			}
		};
	};
	
		$(document).ready(function($) {
		$('.theme-login').click(function() {
			$('.theme-popover-mask').show();
			$('.theme-popover-mask').height($(document).height());
			$('.theme-popover').slideDown(200);
		});

		$('.theme-reg').click(function() {
			$('.theme-popover-mask2').show();
			$('.theme-popover-mask2').height($(document).height());
			$('.theme-popover2').slideDown(200);
		});

		$('.theme-poptit .close').click(function() {
			$('.theme-popover-mask').hide();
			$('.theme-popover').slideUp(200);
		});

		$('.theme-poptit .close2').click(function() {
			$('.theme-popover-mask2').hide();
			$('.theme-popover2').slideUp(200);
		});
	});
	// 登陆
	function login() {
		$
				.ajax({
					url : "LoginServlet",
					type : "POST",
					dataType : "json",
					data : {
						account : $("#account").val(),
						password : $("#password").val()
					},
					success : function(value) {
						alert(value.result);
						$('.theme-popover-mask').hide();
						$('.theme-popover').slideUp(200);
						
						if (value.result == "登陆成功") {
							//var userName = value.userName;
							var userID = value.userID;
							var userAccount = value.userAccount;
							var userPhoto = value.userPhoto;
							$("#userBox")
									.html(
											"
140x140" + "欢迎您,   " + userAccount + "    " + "
" + "" + "" + "
;"
+ "   注销
"
); } else { // 登陆失败清空登陆框的信息 $("#account").val(""); $("#password").val(""); } }, }); }; // 注册 function register() { $.ajax({ url : "RegisterServlet", type : "POST", dataType : "json", data : { regUserName : $("#userName").val(), regAccount : $("#regAccount").val(), regPassword : $("#regPwd2").val() }, success : function(value) { alert(value.result); $('.theme-popover-mask2').hide(); $('.theme-popover2').slideUp(200); }, }); }; // 展示页面 function showMessage() { $("#userInfo").slideDown(200); }; </script> <style type="text/css"> .title { font-size: 30px; margin-left: 20px; margin-right: 20px; } * { margin: 0; padding: 0; list-style-type: none; } a,img { border: 0; } body { font: 12px/180% microsoft yahei; } a { color: #0088DB; text-decoration: none; cursor: pointer } a:hover { color: #2A5E8E } /* input */ input { font-size: 12px; font-size: 100%; font-family: microsoft yahei; outline: none; line-height: normal; color: #444; } .ipt { border: solid 1px #d2d2d2; border-left-color: #ccc; border-top-color: #ccc; border-radius: 2px; box-shadow: inset 0 1px 0 #f8f8f8; background-color: #fff; padding: 4px 6px; height: 21px; line-height: 21px; color: #555; width: 180px; vertical-align: baseline; } .ipt:focus { border-color: #95C8F1; box-shadow: 0 0 4px #95C8F1; } /* btn */ .btn { position: relative; cursor: pointer; display: inline-block; vertical-align: middle; font-size: 12px; font-weight: bold; height: 27px; line-height: 27px; min-width: 52px; padding: 0 12px; text-align: center; text-decoration: none; border-radius: 2px; border: 1px solid #ddd; color: #0088D8; background-color: #0088D8; background: -webkit-linear-gradient(top, #0088D8, #0088D8); background: -moz-linear-gradient(top, #0088D8, #0088D8); background: linear-gradient(top, #0088D8, #0088D8); } input.btn { height: 29px; } .btn:hover { border-color: #0088D8; color: #0088D8; background-color: #0088D8; background: -webkit-linear-gradient(top, #0088D8, #0088D8); background: -moz-linear-gradient(top, #0088D8, #0088D8); background: linear-gradient(top, #0088D8, #0088D8); box-shadow: #0088D8 0 1px 1px 0; } .btn:active,.btn.btn-active { box-shadow: #0088D8 0 1px 2px 0 inset; border-color: #0088D8; } .btn:focus { border-color: #0088D8; outline: none } .btn-primary { border-color: #0088D8; color: #FFFFFF; background-color: #0088D8; background: -webkit-linear-gradient(top, #0088D8, #0088D8); background: -moz-linear-gradient(top, #4D90FE, #4787ED); background: linear-gradient(top, #4D90FE, #4787ED); } .btn-primary:hover { border-color: #0088D8; color: #0088D8; background-color: #0088D8; background: -webkit-linear-gradient(top, #FFFFFF, #FFFFFF); background: -moz-linear-gradient(top, #4D90FE, #357AE8); background: linear-gradient(top, #4D90FE, #357AE8); } .btn-primary:active { box-shadow: #2176D3 0 1px 2px 0 inset; border-color: #3079ED; } .btn-primary:focus { border-color: #4d90fe; outline: none } .oo { margin-right: 5px; } .theme-signin { font-size: 15px; } .theme-popover-mask { z-index: 1; position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: #000; opacity: 0.5; filter: alpha(opacity = 50); -moz-opacity: 0.5; display: none; } .theme-popover-mask2 { z-index: 1; position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: #000; opacity: 0.5; filter: alpha(opacity = 50); -moz-opacity: 0.5; display: none; } .theme-popover { z-index: 9; position: absolute; top: 50%; left: 52%; width: 350px; height: 350px; margin: -150px 0 0 -200px; border-radius: 5px; border: solid 2px #e4e4e4; background-color: #fff; display: none; box-shadow: 0 0 10px #666; background: #fff; } .userInfo { z-index: 10; position: absolute; top: 50px; right: 50px; width: 350px; height: 350px; border-radius: 5px; border: solid 2px #e4e4e4; background-color: #fff; display: none; box-shadow: 0 0 10px #666; background: blue; } .theme-popover2 { z-index: 9; position: absolute; top: 50%; left: 45%; width: 350px; height: 500px; margin: -250px 0 0 -100px; border-radius: 5px; border: solid 2px #e4e4e4; background-color: #fff; display: none; box-shadow: 0 0 10px #666; background: #fff; } .theme-poptit { border-bottom: 1px solid #ddd; padding: 8px; position: relative; height: 24px; } .theme-poptit .close { float: right; color: #999; padding: 5px; margin: -2px -5px -5px; font: bold 14px/14px simsun; text-shadow: 0 1px 0 #ddd } .theme-poptit .close:hover { color: #444; } .theme-poptit2 { border-bottom: 1px solid #ddd; padding: 5px; position: relative; height: 24px; } .theme-poptit2.close { float: right; color: #999; padding: 5px; margin: -2px -5px -5px; font: bold 14px/14px simsun; text-shadow: 0 1px 0 #ddd } .theme-poptit2.close:hover { color: #444; } .theme-popbod { padding: 60px 15px; color: #444; height: 148px; } .dform { height: 40px; padding: 80px 60px 40px; text-align: center; } .theme-signin { margin: -50px -20px -50px 0px; text-align: left; font-size: 14px; } .theme-signin h4 { color: #999; font-weight: 100; margin-bottom: 20px; font-size: 20px; } .theme-signin li { padding-left: 80px; margin-bottom: 15px; } .theme-signin li strong { float: left; margin-left: -80px; width: 80px; text-align: right; line-height: 40px; text-size: 20px; } .theme-signin .btn { margin-top: 30px; margin-right: 83px; margin-bottom: 10px; } .theme-signin p { margin-top: 20px; font-size: 12px; color: #999; } .theme-signin input { height: 30px; } #linkText { font-size:15px; } </style> </head> <body> <div class="navbar navbar-inverse navbar-fixed-top" role="navigation" style="padding-top:10px"> <div class="navbar-header"> <a href="##" class="navbar-brand title">BwLy</a> </div> <ul class="nav nav-pills pull-left"> <li onClick="addClass_(e)"><a id="linkText" href="home.jsp" target="content" id="navBar1" onClick="bar()">首页</a></li> <li onClick="addClass_()"><a id="linkText" href="ThemeServlet" target="content" id="navBar2">贴帖中心</a> </li> <li onclick="addClass_()"><a id="linkText" href="aboutUs.jsp" target="content" id="navBar6">关于我们</a> </li> </ul> <div class="pull-right" id="userBox" style="margin-right:40px; margin-top:8px" style="positon:absolute; right:30px; top: 10px"> &nbsp; &nbsp; &nbsp; &nbsp; <a class="btn btn-primary theme-login" id="login" href="javascript:;">登录</a> <a class="btn btn-primary theme-reg" id="reg" href="javascript:;">注册</a> </div> </div> <!-- 登陆页面 --> <div class="theme-popover-mask"></div> <div class="theme-popover"> <div class="theme-poptit"> <a href="javascript:;" title="关闭" class="close">×</a> <h3>登录</h3> </div> <form class="theme-popbod dform"> <div class="theme-signin"> <p> <strong>用户名:&nbsp;&nbsp;&nbsp;&nbsp;</strong><input class="ipt" type="text" id="account" placeholder="用户名" size="20" /> </p> <p> <strong>&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong><input class="ipt" type="password" id="password" placeholder="用户密码" size="20" /> </p> <div style="margin-top:20px"> <input class="btn btn-primary" type="button" onClick="login()" value=" 登 录 " style="margin-left: 0px;" /> <input class="btn btn-primary" type="reset" name="reset" value=" 重 置 " style="margin-right: -10px;" /> </div> </div> </form> </div> <!-- 注册页面 --> <div class="theme-popover-mask2"></div> <div class="theme-popover2"> <div class="theme-poptit"> <a href="javascript:;" title="关闭" class="close2">×</a> <h3>注册</h3> </div> <form class="theme-popbod dform"> <div class="theme-signin"> <p> <strong>&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong><input class="ipt" type="text" id="regAccount" placeholder="用户名" size="20" /> <font color="#0088D8"><nobr id="name1_msg"></nobr> </font> </p> <p> <strong>&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;</strong> <input class="ipt" type="text" id="userName" placeholder="取一个专属的昵称吧" size="20" /> <font color="#0088D8"><nobr id="name2_msg"></nobr> </font> </p> <p> <strong>&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong><input class="ipt" type="password" id="regPwd1" placeholder="请输入你的密码" size="20" /> <font color="#0088D8"><nobr id="password1_msg"></nobr> </font> </p> <p> <strong>确认密码:&nbsp;&nbsp;&nbsp;</strong><input class="ipt" type="password" id="regPwd2" placeholder="请再次输入你的密码" size="20" /> <font color="#0088D8"><nobr id="password2_msg"></nobr> </font> </p> <div style="margin-top:20px"> <input class="btn btn-primary" type="button" onClick="register()" value=" 注 册 " style="margin-left: -10px;" /> <input class="btn btn-primary" type="reset" name="reset" value=" 重 置 " style="margin-right: -10px;" /> </div> </div> </form> </div> <div id="userInfo"></div> <div style="width:100%"> <iframe style="width:100%; height:100%;" src="home.jsp" name="content" frameborder="no"></iframe> </div> </body> </html>

你可能感兴趣的:(java,前端,servlet,mysql,javascript)