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

📄 forum.java

📁 BBS论坛系统由JAVA和JSP实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:


			dbc.executeUpdate();
			dbc.close();
			return "dispbbs.jsp?forumID="+forumID+"&rootID="+rootID+"&announceID="+announceID+"#"+announceID;
  		}
  		catch(UserNotFoundException e){
  			throw new Exception("没有发现用户");
  		}
  		catch(Exception e){
  			e.printStackTrace();
  			throw new Exception("<Br>"+"<li>"+e.getMessage());
		}
	}
	public String masterSaveMSG(HttpServletRequest request,HttpServletResponse response) throws Exception{

		String userName=GCookie.getCookieValue(request,"UJBBUName","");

		//String userPassword=ParamUtil.getString(request,"userPassword","");
		String sql="";
		String char_changed = "[align=right][此贴子已经被"+userName+"于"+Format.getDateTime()+"编辑过][/align]";
        	try{

        		User tempUser=SkinUtil.checkUser(request,response,4);
				DBConnect dbc=new DBConnect();
				ResultSet rs;
        		int forumID=ParamUtil.getInt(request,"forumID");
				int announceID=ParamUtil.getInt(request,"announceID");
				int rootID=ParamUtil.getInt(request,"rootID");

        		String subject=ParamUtil.getString(request,"subject","");
        		String content=ParamUtil.getString(request,"content","")+"\n\n\n\n"+char_changed;
        		String expression=ParamUtil.getString(request,"expression","");
        		int signFlag=ParamUtil.getInt(request,"signFlag",1);
        		int emailFlag=ParamUtil.getInt(request,"emailFlag",0);
        		if(subject.equals("")) throw new Exception("没有主体文字");

			sql="update bbs.bbs1 set Topic=?,Body=?,DateAndTime=getdate(),length=?,ip=?,expression=?,signflag=?,emailflag=? where announceID=?";
			dbc.prepareStatement(sql);
			dbc.setBytes(1,(new String(subject.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setBytes(2,(new String(content.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setInt(3,content.length());
			dbc.setString(4,request.getRemoteAddr());
			dbc.setString(5,expression);
			dbc.setInt(6,signFlag);
			dbc.setInt(7,emailFlag);
			dbc.setInt(8,announceID);


			dbc.executeUpdate();
			dbc.close();
			return "dispbbs.jsp?forumID="+forumID+"&rootID="+rootID+"&announceID="+announceID+"#"+announceID;
  		}
  		catch(UserNotFoundException e){
  			throw new Exception("没有发现用户");
  		}
  		catch(Exception e){
  			e.printStackTrace();
  			throw new Exception("<Br>"+"<li>"+e.getMessage());
		}
	}
	public String addTopic(HttpServletRequest request,HttpServletResponse response) throws Exception{

		String userName=ParamUtil.getString(request,"userName","");
		String userPassword=ParamUtil.getString(request,"userPassword","");
		String sql="";

        	try{

        		//SkinUtil.userLogin(request,response,2);
        		User tempUser=new User(userName,userPassword,2);
				DBConnect dbc=new DBConnect();
        		int forumID=ParamUtil.getInt(request,"forumID",1);
        		String subject=ParamUtil.getString(request,"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",1);
        		int emailFlag=ParamUtil.getInt(request,"emailFlag",0);
        		if(subject.equals("")) throw new Exception("没有主体文字");

			sql="insert into bbs.bbs1(Boardid,ParentID,Child,username,topic,body,DateAndTime,hits,length,rootid,layer,orders,ip,Expression,locktopic,signflag,emailflag,istop,isbest,isvote,times) values "+
				"("+
				forumID+",0,0,?,?,?,'"+
				Format.getDateTime()+"',0,"+
				content.length()+",0,1,0,'"+request.getRemoteAddr()+"','"+
				expression+".gif',0,"+signFlag+","+emailFlag+",0,0,"+isVote+",0)";

			dbc.prepareStatement(sql);
			dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setBytes(2,(new String(subject.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setBytes(3,(new String(content.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.executeUpdate();
			ResultSet rs=dbc.executeQuery("select announceid from bbs.bbs1 order by announceid desc");
	        	rs.next();
	        	int announceID=rs.getInt(1);
				voteID=announceID;
			sql="update bbs.bbs1 set rootid="+announceID+",times="+announceID+" where announceid="+announceID;
			dbc.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;
			ResultSet tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)-day(getdate())=0 and boardid="+forumID);
	    		tmprs.next();
	    		int forumToday=tmprs.getInt(1);
	    		tmprs=null;
			sql="update bbs.board set lastpostuser=?,lastposttime='"+Format.getDateTime()+"',lastbbsnum=lastbbsnum+1,lasttopicnum=lasttopicnum+1,todaynum="+forumToday+",lastrootid="+announceID+",lasttopic=? where  boardid="+forumID;
			dbc.clearParameters();
			dbc.prepareStatement(sql);
			dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setBytes(2,(new String(shortTopic.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.executeUpdate();
			tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)-day(getdate())=0");
	    		tmprs.next();
	    		int allTodays=tmprs.getInt(1);
			dbc.executeUpdate("update bbs.config set topicnum=topicnum+1,bbsnum=bbsnum+1,todayNum="+allTodays);
			dbc.close();
			ForumPropertiesManager.resetManager();
			return "dispbbs.jsp?forumID="+forumID+"&rootID="+announceID+"&announceID="+announceID;
  		}
  		catch(UserNotFoundException e){
  			throw new Exception("没有发现用户");
  		}
  		catch(Exception e){
  			e.printStackTrace();
  			throw new Exception("<Br>"+"<li>数据库操作失败,请以后再试");
		}
	}
	public String addMSG(HttpServletRequest request,HttpServletResponse response)throws UserNotFoundException ,Exception{
		//try{
			String userName=ParamUtil.getString(request,"userName","");
			String userPassword=ParamUtil.getString(request,"userPassword","");
			//SkinUtil.userLogin(request,response,3);
			User tempUser=new User(userName,userPassword,3);
        		DBConnect dbc=new DBConnect();
        		int forumID=this.forumID;
        		String subject=ParamUtil.getString(request,"subject","");
        		String content=ParamUtil.getString(request,"content","");
        		String expression=ParamUtil.getString(request,"expression","face7.gif");
				String sql="";
				int rootID=ParamUtil.getInt(request,"rootID");
				ResultSet rs;
				dbc.prepareStatement("select locktopic from bbs.bbs1 where announceid="+rootID);
				rs=dbc.executeQuery();
				if(!rs.next()){
					dbc.close();
					throw new Exception("<li>对不起,没有发现此主题!</li>");
				}
				else{
					//rs.next();
					if(rs.getInt(1)==1||rs.getInt(1)==2){
						dbc.close();
						throw new Exception("对不起,此帖子已经锁定,您不能回复!");
					}
				}

				int iLayer,iOrders;
        		int signFlag=ParamUtil.getInt(request,"signFlag",1);
        		int emailFlag=ParamUtil.getInt(request,"emailFlag",0);

				int parentID=ParamUtil.getInt(request,"parentID",rootID);
				sql="select layer,orders from bbs.bbs1 where announceid="+parentID;
				rs=dbc.executeQuery(sql);
				if(rs.next()){
					if(rs.getString(1)!=null)
						iLayer=0;
					else
						iLayer=rs.getInt(1);
					if(rs.getString(2)!=null)
						iOrders=0;
					else
						iOrders=rs.getInt(2);
				}
				else{
					iLayer=0;
					iOrders=0;
				}
				rs.close();
				if (rootID!=0){
					iLayer=iLayer+1;
					dbc.executeUpdate("update bbs.bbs1 set orders=orders+1 where rootid="+rootID+" and orders>"+iOrders);
					iOrders=iOrders+1;
		     	}
        		sql="insert into bbs.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,"+
				"?,?,?,'"+
				Format.getDateTime()+"',0,"+
				content.length()+","+rootID+","+iLayer+","+iOrders+",'"+request.getRemoteAddr()+"','"+
				expression+"',0,"+signFlag+","+emailFlag+",0,0,0,0)";
			dbc.prepareStatement(sql);
			dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setBytes(2,(new String(subject.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setBytes(3,(new String(content.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.executeUpdate();
			rs=dbc.executeQuery("select announceid from bbs.bbs1 order by announceid desc");
        	rs.next();
        	int announceID=rs.getInt(1);
			sql="update bbs.bbs1 set child=child+1,times="+announceID+" where rootID="+rootID;
          		dbc.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;
			ResultSet tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)-day(getdate())=0 and boardid="+forumID);
	    		tmprs.next();
	    		int forumToday=tmprs.getInt(1);
	    		tmprs=null;

			sql="update bbs.board set lastpostuser=?,lastposttime='"+Format.getDateTime()+"',lastbbsnum=lastbbsnum+1,todaynum="+forumToday+",lastrootid="+rootID+",lasttopic=? where  boardid="+forumID;
			dbc.clearParameters();
			dbc.prepareStatement(sql);
			dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setBytes(2,(new String(shortTopic.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.executeUpdate();
			tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)-day(getdate())=0");
	    		tmprs.next();
	    		int allTodays=tmprs.getInt(1);
			dbc.executeUpdate("update bbs.config set bbsnum=bbsnum+1,todayNum="+allTodays);
			dbc.close();
			ForumPropertiesManager.resetManager();
			return "dispbbs.jsp?forumID="+forumID+"&rootID="+rootID+"&announceID="+announceID+"#"+announceID;


	}
	public String addVote(HttpServletRequest request,HttpServletResponse response) throws Exception{
		try{

			String vote=ParamUtil.getString(request,"vote");
			String userName=ParamUtil.getString(request,"userName","");
			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);
			DBConnect dbc=new DBConnect("insert into bbs.vote(announceID,vote,voteNum,voteType,voteUser) values(?,?,?,?,?)");
			dbc.setInt(1,voteID);
			dbc.setBytes(2,(new String(vote.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.setString(3,voteNum);
			dbc.setInt(4,voteType);
			dbc.setBytes(5,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
			dbc.executeUpdate();
			dbc.close();
			return url;
		}
		catch(Exception e){
			e.printStackTrace();
			throw new Exception(e.getMessage());
		}

	}
	public ForumVote getForumVote(int announceID) throws Exception{
		DBConnect dbc=new DBConnect("select * from bbs.vote where announceID=?");
		dbc.setInt(1,announceID);
		ResultSet rs=dbc.executeQuery();
		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 {
		String userName=GCookie.getCookieValue(request,"UJBBUName","");
		String userPassword=GCookie.getCookieValue(request,"UJBBUPSW","");
		User tempUser=new User(userName,userPassword,1);
		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])+"|";

		}
		DBConnect dbc=new DBConnect("select * from bbs.vote where announceID="+announceID);
		ResultSet rs=dbc.executeQuery();
		rs.next();
		String voteUser=rs.getString(5);
		voteUser+="|"+userName;
		dbc.prepareStatement("update bbs.vote set voteNum='"+voteNum+"',voteUser=? where announceID="+announceID);
		dbc.setBytes(1,(new String(voteUser.getBytes("ISO-8859-1"),"GBK")).getBytes());
		dbc.executeUpdate();

		return "dispbbs.jsp?forumID="+forumID+"&rootID="+announceID+"&announceID="+announceID;



	}
}

⌨️ 快捷键说明

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