⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forum.java

📁 一个用jsp写的完整的论坛源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			// 缓存
			CacheManager.getCache(ENV.FORUM_NEWS).remove(
					String.valueOf(announceID));
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(announceID));
			return "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + announceID + "#" + announceID;
		} catch (UserNotFoundException e) {
			throw new Exception("没有发现用户");
		} catch (Exception e) {
			log.error("版主编辑帖子出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public String addTopic(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		String userName = ParamUtil.getString(request, "userName", "guest");
		String sql = "";
		try {
			// 发新帖子,增加用户的经验、魅力值
			SkinUtil.checkUser(request, response, 2);
			//
			int forumID = ParamUtil.getInt(request, "forumID", 1);
			String subject = ParamUtil.getString(request, "subject", "");
			subject = StringUtil.changeToFull(subject);
			String content = ParamUtil.getString(request, "content", "");
			String expression = ParamUtil.getString(request, "expression", "");
			int isVote = ParamUtil.getInt(request, "isVote", 0);
			int signFlag = ParamUtil.getInt(request, "signFlag", 0);
			int emailFlag = ParamUtil.getInt(request, "emailFlag", 0);
			int viewMode = ParamUtil.getInt(request, "viewMode", 0);
			int viewNumber = ParamUtil.getInt(request, "viewNumber", 0);
			if (subject.equals("")){
				throw new Exception("没有主体文字");
			}
			jw.setAutoClose(false);
			sql = "insert into " + BBSConst.TABLE_BBS1 + "(Boardid,ParentID,Child,username,topic,body,DateAndTime,hits,length,rootid,layer,orders,ip,Expression,locktopic,signflag,emailflag,istop,isbest,isvote,times,viewmode,viewnumber) values "
					+ "("
					+ forumID
					+ ",0,0,?,?,?,'"
					+ DateUtil.getLocalDate()
					+ "',0,"
					+ content.length()
					+ ",0,1,0,'"
					+ request.getRemoteAddr()
					+ "',?,0,"
					//+ expression
					//+ ""
					+ signFlag + "," + emailFlag + ",0,0," + isVote + ",0,"+viewMode+","+viewNumber+")";

			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, subject);
			jw.setString(3, content);
			jw.setString(4, expression);
			jw.executeUpdate();
			//
			int announceID = jw.doIntSearch("select announceid from " + BBSConst.TABLE_BBS1 + " order by announceid desc");
			voteID = announceID;
			sql = "update " + BBSConst.TABLE_BBS1 + " set rootid=" + announceID + ",times="
					+ announceID + " where announceid=" + announceID;
			jw.executeUpdate(sql);
			String shortTopic = "";
			if ("".equals(subject)){
				if (content.length() > 21){
					shortTopic = content.substring(0, 20);
				}else{
					shortTopic = content;
				}
			}else if (subject.length() > 21){
				shortTopic = subject.substring(0, 20);
			}else{
				shortTopic = subject;
			}
			int forumToday = jw.doIntSearch("Select count(announceid) from " + BBSConst.TABLE_BBS1 + " Where to_days(dateandtime)-to_days(Now())=0 and boardid="
							+ forumID);
			//
			sql = "update " + BBSConst.TABLE_BOARD + " set lastpostuser='"
					+ userName
					+ "',lastposttime='"
					+ DateUtil.getLocalDate()
					+ "',lastbbsnum=lastbbsnum+1,lasttopicnum=lasttopicnum+1,todaynum="
					+ forumToday + ",lastrootid=" + announceID + ",lasttopic=?"
					+ " where  boardid=" + forumID;
			jw.clearParameters();
			jw.prepareStatement(sql);
			jw.setString(1, shortTopic);
			jw.executeUpdate();
			//
			int allTodays = jw.doIntSearch("Select count(announceid) from " + BBSConst.TABLE_BBS1 + " Where to_days(dateandtime)-to_days(Now())=0");
			jw.executeUpdate("update " + BBSConst.TABLE_CONFIG + " set topicnum=topicnum+1,bbsnum=bbsnum+1,todayNum="
							+ allTodays);
			//
			CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
			CacheManager.getCache(ENV.FORUM_USER).remove(userName);
			//
			ForumPropertiesManager.resetManager();
			return "dispbbs.jsp?forumID=" + forumID + "&rootID=" + announceID
					+ "&announceID=" + announceID;
		} catch (UserNotFoundException e) {
			throw new Exception("没有发现用户");
		} catch (Exception e) {
			log.error("添加主题出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void emailReplay(int announceID, String title, String content) throws Exception{
		JdbcWrapper rs = new JdbcWrapper("select a.emailflag,b.useremail from " + BBSConst.TABLE_BBS1 + " a,"+BBSConst.TABLE_USER+" b where a.username=b.username and a.announceid="+announceID);
		if(rs.next()){
			int emailFlag = rs.getInt(1);
			if(emailFlag==1){
				SendMail.sendMail(rs.get(2), title, content);
			}
		}
	}
	
	public String addMSG(HttpServletRequest request,
			HttpServletResponse response) throws UserNotFoundException,
			Exception {
		JdbcWrapper jw = new JdbcWrapper();
		//
		String userName = ParamUtil.getString(request, "userName", "guest");
		try {
			// 回帖子,增加用户的经验,魅力值
			SkinUtil.checkUser(request, response, 3);
			int forumID = this.forumID;
			String subject = ParamUtil.getString(request, "subject", "");
			subject = StringUtil.changeToFull(subject);
			String content = ParamUtil.getString(request, "content", "");
			if ("".equals(content)) {
				throw new Exception("请输入回复内容!");
			}
			String expression = ParamUtil.getString(request, "expression","");
			String sql = "";
			int rootID = ParamUtil.getInt(request, "rootID");
			jw.setAutoClose(false);
			sql = "select locktopic from " + BBSConst.TABLE_BBS1 + " where announceid=" + rootID;
			jw.executeQuery(sql);
			if (!jw.next()) {
				throw new Exception("<li>对不起,没有发现此主题!</li>");
			} else {
				if (jw.getInt(1) == 1 || jw.getInt(1) == 2) {
					throw new Exception("对不起,此帖子已经锁定,您不能回复!");
				}
			}
			int iLayer, iOrders;
			int signFlag = ParamUtil.getInt(request, "signFlag", 0);
			int emailFlag = ParamUtil.getInt(request, "emailFlag", 0);
			int parentID = ParamUtil.getInt(request, "parentID", rootID);
			sql = "select layer,orders from " + BBSConst.TABLE_BBS1 + " where announceid=" + parentID;
			jw.executeQuery(sql);
			if (jw.next()) {
				iLayer = jw.getInt(1);
				iOrders = jw.getInt(2);
			} else {
				iLayer = 0;
				iOrders = 0;
			}
			if (rootID != 0) {
				iLayer = iLayer + 1;
				jw.executeUpdate("update " + BBSConst.TABLE_BBS1 + " set orders=orders+1 where rootid="
						+ rootID + " and orders>" + iOrders);
				iOrders = iOrders + 1;
			}

			sql = "insert into " + BBSConst.TABLE_BBS1 + "(Boardid,ParentID,Child,username,topic,body,DateAndTime,hits,length,rootid,layer,orders,ip,Expression,locktopic,signflag,emailflag,istop,isbest,isvote,times) values "
					+ "("
					+ forumID
					+ ","
					+ parentID
					+ ",0,"
					+ "?,?,?,'"
					+ DateUtil.getLocalDate()
					+ "',0,"
					+ content.length()
					+ ","
					+ rootID
					+ ","
					+ iLayer
					+ ","
					+ iOrders
					+ ",'"
					+ request.getRemoteAddr()
					+ "',?,0,"
					//+ expression
					//+ "',0,"
					+ signFlag + "," + emailFlag + ",0,0,0,0)";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, subject);
			jw.setString(3, content);
			jw.setString(4, expression);
			jw.executeUpdate();
			//
			int announceID = jw
					.doIntSearch("select announceid from " + BBSConst.TABLE_BBS1 + " order by announceid desc limit 0,1");
			sql = "update " + BBSConst.TABLE_BBS1 + " set child=child+1,times=" + announceID
					+ " where rootID=" + rootID;
			jw.executeUpdate(sql);
			String shortTopic = "";

			if ("".equals(subject)){
				if (content.length() > 21){
					shortTopic = content.substring(0, 20);
				}else{
					shortTopic = content;
				}
			}else if (subject.length() > 21){
				shortTopic = subject.substring(0, 20);
			}else{
				shortTopic = subject;
			}
			int forumToday = jw
					.doIntSearch("Select count(announceid) from " + BBSConst.TABLE_BBS1 + " Where to_days(dateandtime)-to_days(Now())=0 and boardid="
							+ forumID);

			sql = "update " + BBSConst.TABLE_BOARD + " set lastpostuser='" + userName
					+ "',lastposttime='" + DateUtil.getLocalDate()
					+ "',lastbbsnum=lastbbsnum+1,todaynum=" + forumToday
					+ ",lastrootid=" + rootID + ",lasttopic=?"
					+ " where  boardid=" + forumID;
			jw.clearParameters();
			jw.prepareStatement(sql);
			jw.setString(1, shortTopic);
			jw.executeUpdate();
			//
			int allTodays = jw
					.doIntSearch("Select count(announceid) from " + BBSConst.TABLE_BBS1 + " Where to_days(dateandtime)-to_days(Now())=0");
			jw.executeUpdate("update " + BBSConst.TABLE_CONFIG + " set bbsnum=bbsnum+1,todayNum="
					+ allTodays);
			//
			CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(parentID));
			CacheManager.getCache(ENV.FORUM_USER).remove(userName);
			//
			ForumPropertiesManager.resetManager();
			//发邮件
			String ret = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
			+ "&announceID=" + announceID + "#" + announceID;
			//取得配置论坛URL
			String forumURL = ForumPropertiesManager.getString("ForumURL");
			String url = StringUtil.substring(forumURL, forumURL.lastIndexOf("/")) + "/" + ret;
			emailReplay(parentID,"您在鲤鱼论坛上的帖子有回复了!","帖子地址:<a href='"+url+"' target=_blank>"+url+"</a>");
			
			return ret;
		} catch (Exception e) {
			log.error("回复主题出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public String addVote(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			String vote = ParamUtil.getString(request, "vote");
			vote = StringUtil.changeToFull(vote);
			String userName = ParamUtil.getString(request, "userName", "guest");
			if (vote == null){
				throw new Exception("<li>请您输入投票内容</li>");
			}
			String voteNum = "";

			String reg = "(\r|\n)";
			String[] tempString = vote.split(reg);

			for (int i = 0; i < tempString.length; i++) {
				if (!tempString[i].trim().equals("")) {
					if (i == tempString.length - 1) {
						voteNum += "0";
					} else {
						voteNum += "0|";
					}
				}
			}
			int voteType = ParamUtil.getInt(request, "voteType", 0);
			//
			String url = this.addTopic(request, response);
			//
			jw.prepareStatement("insert into " + BBSConst.TABLE_VOTE + "(announceID,vote,voteNum,voteType,voteUser) values(?,?,?,?,?)");
			jw.setInt(1, voteID);
			jw.setString(2, vote);
			jw.setString(3, voteNum);
			jw.setInt(4, voteType);
			jw.setString(5, userName);
			jw.executeUpdate();
			return url;
		} catch (Exception e) {
			log.error("添加新投票出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public ForumVote getForumVote(int announceID) throws Exception {
		JdbcWrapper rs = new JdbcWrapper("select * from " + BBSConst.TABLE_VOTE + " where announceID="
				+ announceID);
		if (rs.next()) {
			ForumVote forumVote = new ForumVote();
			forumVote.setVoteID(rs.getInt(1));
			forumVote.setAnnounceID(rs.getInt(2));
			forumVote.setVote(rs.getString(3));
			forumVote.setVoteNum(rs.getString(4));
			forumVote.setVoteUser(rs.getString(5));
			forumVote.setVoteType(rs.getInt(6));
			return forumVote;
		} else{
			throw new Exception("<li>错误,对不起,没有发现投票!</li>");
		}
	}

	public String addVoteNum(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		String userName = GCookie.getCookieValue(request, "UJBBUName", "");
		try {
			SkinUtil.checkUser(request, response, 3);
			//
			int announceID = ParamUtil.getInt(request, "announceID");
			int forumID = ParamUtil.getInt(request, "forumID");
			ForumVote theVote = this.getForumVote(announceID);
			String voteNum = "";
			int[] voteNumS = theVote.getVoteNumS();
			if (theVote.getUserSign(userName)) {
				throw new Exception("<li>对不起,您已经投票了!</li>");
			} else {
				if (theVote.getVoteType() == 0) {
					int postID = ParamUtil.getInt(request, "postVote");
					voteNumS[postID]++;
				} else {
					for (int i = 0; i < voteNumS.length; i++) {
						if (ParamUtil.getString(request, "postVote_" + (i)) != null)
							voteNumS[i]++;
					}
				}
				for (int i = 0; i < voteNumS.length; i++)
					if (i == voteNumS.length - 1)
						voteNum += Integer.toString(voteNumS[i]);
					else
						voteNum += Integer.toString(voteNumS[i]) + "|";
			}
			String voteUser = jw.doSearch("select voteuser from " + BBSConst.TABLE_VOTE + " where announceID=" + announceID);
			voteUser += "|" + userName;
			String sql = "update " + BBSConst.TABLE_VOTE + " set voteNum='" + voteNum + "',voteUser='"
					+ voteUser + "' where announceID=" + announceID;
			jw.executeUpdate(sql);

			return "dispbbs.jsp?forumID=" + forumID + "&rootID=" + announceID
					+ "&announceID=" + announceID;
		} catch (Exception e) {
			log.error("投票出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -