Plus a voting function for the JIVE forum

zhaozj2021-02-11  208

What is JIVE doesn't say much, I have used some forum voting, and I like the voting of the Journalism Forum. The operation is simple, choose a radio or multiple selected, then enter the voting option, each line is one option, up to 10. I add this feature into the jive, build two new tables: Create Table Jivevote (Voteid Int Not Null, - Voting ID, THEPE INT NULL with JIVE THEPE INT NOT NULL, - Voting type, radio) votenum int NOT NULL, - the number of votetxt text NOT NULL, - vote text content1 int default 0, content2 int default 0, content3 int default 0, content4 int default 0, content5 int default 0, content6 int default 0, content7 INT Default 0, Content8 Int Default 0, Content9 Int Default 0, Content10 Int Default 0, Primary Key (Voteid));

Create Table JivevoteeRecord (Voteid Int Not Null, - Voting ID, THEADID with JIVE) Keep Userid Int Not Null - Remove Voted Vote Users); write a poll.java file, write to static methods for convenience, Package com.jivesoftware.forum.database; // This can call the connection pool to increase the subject voting, the user submits the voting content, whether it is only selected Public Static Void AddvoteThread (Long Voteid, String VotetXT, Boolean Single, Int Votenum) {String Sqlstr = " insert into jivevote (voteid, type, votetxt, votenum) values ​​"(,,,????); Connection con = null; PreparedStatement stmt = null; try {con = ConnectionManager.getConnection (); stmt = con.prepareStatement ( SQLSTR); Stmt.Setlong (1, voteid); Stmt.setint (2, SINGLE? 0: 1); Stmt.setString (3, votetxt); Stmt.setint (4, votenum); stmt.executeUpdate () Catch (SQLEXCEPTION SQLE) {sqle.printStackTrace ();} finally {try {stmt.close ();} catch (exception e) { E.PrintStackTrace ();} try {con.close ();} catch (exception e) {E.PrintStackTrace ();}}} Executive voting operation, ThreadID is established when the newly established vote, the voted array is options public static boolean vote (long threadID, int [] voted, long userID) {if (isVoted (threadID, userID)) {return false;} Connection con = null; PreparedStatement stmt = null; try {con = ConnectionManager.getConnection ( ); For (int i = 0; IIF (voted [i]! = 0) {

Stmt = con.preparestatement ("Update Jivevote SET Content" Voted [i] "= Content" voted [i] " 1 WHERE VOTEID =?"); Stmt.Setlong (1, threadID);

Stmt.executeUpdate ();

}

}

STMT = Con.PrepareStatement ("INSERT INTO JIVEVOTERECORD (VOTEID, Userid) VALUES (?,?)");

Stmt.setlong (1, threadid);

Stmt.setlong (2, userid);

Stmt.executeUpdate ();

}

Catch (Sqlexception SQLE)

{

Sqle.printStackTrace ();

}

Finally

{

Try

{

Stmt.close ();

}

Catch (Exception E)

{

E.PrintStackTrace ();

}

Try

{

C. close ();

}

Catch (Exception E)

{

E.PrintStackTrace ();

}

}

Return True;

}

Decision has been voted

Public Static Boolean Isvot (Long ThreadID, Long UserId) {

Connection con = NULL;

PreparedStatement Stmt = NULL;

Boolean Ret = False;

Try

{

Con = ConnectionManager.getConnection ();

Stmt = con.preparestatement ("SELECT Voteid from jivevoterecord where voteid =? and userid =?");

Stmt.setlong (1, threadid);

Stmt.setlong (2, userid);

ResultSet RS = stmt.executeQuery ();

Ret = rs.next ();

}

Catch (Sqlexception SQLE)

{

Sqle.printStackTrace ();

}

Finally

{

Try

{

Stmt.close ();

}

Catch (Exception E)

{

E.PrintStackTrace ();

}

Try

{

C. close ();

}

Catch (Exception E)

{

E.PrintStackTrace ();

}

}

Return Ret;

}

Get a voting content

Public Static String GetVoteView (long threadid, long user) {

Connection con = NULL;

PreparedStatement Stmt = NULL;

StringBuffer SB = new stringbuffer ();

Sb.append ("

"); Boolean isVotedUser = false; try {con = ConnectionManager.getConnection (); stmt = con.prepareStatement (" select * from jivevote where voteid = ");? Stmt.setLong (1, threadID); ResultSet rs = stmt. ExecuteQuery (); string s = ""; if (rs.next ()) {INT TYPE = rs.Getint ("type"); int votenum = rs.getinT ("votenum"); sb.append ("") Sb.append ("

"); String votetxt = rs.getstring (" votetxt "); string [] OPTS = votetxt.split (" / n "); for (int i = 1; i <= opts.length; i ) {sb.append ("

"); If (i == 1) {s =" checked ";} else {s =" ";} if (Type == 1) {sb.append ("

" i ". "");} else {sb.append ("

" i ". " OPTS [i-1] " votes: " rGETINT (" Content " i) " ");} sb.append ("

");}} Isvoteduser = isvoted (threadid, userid); if (! Isvoteduser) {sb.append ("

");} Else {sb.append ("

You have already voted ");}} catch (sqlexception sqle) {sqle.printStackTrace ();} finally {try {stmt.close ();} catch (exception e) {E.PrintStackTrace ();} try { Cause ();} catch (exception e) {E.PrintStackTrace ();}} sb.append ("

Return sb.toString ();

}

Add a new JSP:

<%

/ **

* $ RCSFILE: Addvote.jsp, V $

* $ Revision: 1.13.4.2 $

* $ DATE: 2002/05/21 20:38:12 $

* /

%>

<% @ Page Import = "java.net. *,

Java.text. *,

Java.util. *,

com.jiveSoftware.UTIL. *,

com.jivesoftware.forum. *,

com.jivesoftware.forum.util. * "

ErrorPage = "Error.jsp"

%>

<% @ include file = "postutils.jsp"%> <% @ include file = "global.jsp"%> <% @ page contenttype = "text / html; charSet = GBK"%> <% // put the request URI and query string in the session as an attribute // This is done so the error.jsp and auth.jsp pages can figure out what // page sent it an error and redirect appropriately setRedirectURL (request);..%> <% if (pageUser == null) {throw new UnauthorizedException ( ". you do not have permission operation");} long forumID = ParamUtils.getLongParameter (request, "forum", - 1L); long threadID = ParamUtils.getLongParameter (request, "thread ", -1L); int type = paramutils.getintParameter (Request," Type ", 0); int votenum = paramutils.getInetParameter (Request," votenum ", 0); string opt= paramutils.getParameter (Request," CHK " ); forumFactory = com.jivesoftware.forum.database.DbForumFactory.getInstance (); // Load the forum Forum forum = forumFactory.getForum (forumID); ForumThread thread = forum.getThread (threadID); int opti = 1; try { Opti = INTEGER.PARSEINT (OPT);} catch (exception e) {} if (type == 0) {int [] OPTS = New INT [1]; OPTS [0] = Opti; Helper.vote (threadid, opts, pageuser.getid ());} else {if (votenum> 0) {int [] OPTS = new int [votenum]; int i = 0; Enumeration E = Request.getParameterNames (); while (E.hasMoreElements ()) {string VID = (String) E.NEXTELEMENT (); if (Vid.StartSwith ("chK_")) {OPTS [i] = Integer.Parseint (Request.GetParameter (VID)); i ;}} helper.vote (threadid, opts, pageuser.getid ());}}} response.sendredirect ("thread.jsp? Forum =" forumid "& thread = " threadID);%>

Add voting in Post.jsp ... string votetxt = paramutils.getParameter (Request, "VotetXT"); int vottype = paramutils.GetIntParameter (Request, "Vottype", 0); ... IF (Dopost && Subjectok && Bodyok ) {if (fromPreview) {newMessage = postMessage (request, reply, forumFactory, forum, thread, messageID, pageUser, name, email, subject, body);} else {newMessage = postMessage (request, reply, forumFactory, forum, thread , MessageID, Pageuser, Name, Email, Subject, Body;} thread = newMessage.GetforumThread (); // Add voting IF (vote && votetxt! = Null&&! Reply) {int votenum = 0; string [] voteoptions = votetxt.split ("/ n"); if (voteoptions.length> = 10) {votenum = 10;} else {votenum = voteoptions.Length;} votetxt = "; for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-5765.html

New Post(0)