diff --git a/Aboutus.jsp b/Aboutus.jsp new file mode 100644 index 0000000..1f83dcb --- /dev/null +++ b/Aboutus.jsp @@ -0,0 +1,137 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +About us + + + + + + +
+ +
+
团队成员:吴钟富,唐震,卓晨曦,庄梓淇
+ + + + diff --git a/AuthorController.java b/AuthorController.java new file mode 100644 index 0000000..9d23a16 --- /dev/null +++ b/AuthorController.java @@ -0,0 +1,386 @@ +package com.controller; + +import java.io.IOException; +import java.sql.SQLException; +import java.sql.Timestamp; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import com.service.DB; +import com.javaBean.Administrator; +import com.javaBean.Article; +import com.javaBean.Author; + +/** + * Servlet implementation class com.controller.AuthorController + */ +@WebServlet("/com.controller.AuthorController") +public class AuthorController extends HttpServlet { + HttpSession session; + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public AuthorController() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String page = request.getParameter("page"); + + if(page == null) + { + request.getRequestDispatcher("AuthorHome.jsp").forward(request, response); + } + + else + { + doPost(request, response); + } + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String page = request.getParameter("page"); + HttpSession session=request.getSession(); + + if(page.equals("admin")) + { + String email = request.getParameter("email"); + String password = request.getParameter("password"); + session.setAttribute("email",email); + Administrator a = new Administrator(); + a.setEmail(email); + a.setPassword(password); + + DB db = new DB(); + boolean status = false; + + try + { + status = db.checkAdministrator(a); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + if(status) + { + + +// request.setAttribute("email",email); + request.getRequestDispatcher("AuthorHome.jsp").forward(request, response); + } + + else + { + request.setAttribute("msg", "invalid"); + request.getRequestDispatcher("Author.jsp").forward(request, response); + } + } + + if(page.equals("register")) + { + request.getRequestDispatcher("AuthorRegister.jsp").forward(request, response); + } + + if(page.equals("register-form")) + { + String email = request.getParameter("email"); + String password = request.getParameter("password"); + String conpassword = request.getParameter("conpassword"); + + if(password.equals(conpassword)) + { + Author a = new Author(); + a.setEmail(email); + a.setPassword(password); + + DB db = new DB(); + + try + { + db.addAuthor(a); + session.setAttribute("email",email); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + request.getRequestDispatcher("Author.jsp").forward(request, response); + } + + else + { + request.getRequestDispatcher("AuthorRegister.jsp").forward(request, response); + } + } + + if(page.equals("home")) + { + String email = request.getParameter("email"); + request.setAttribute("email",email); + request.getRequestDispatcher("AuthorHome.jsp").forward(request, response); + } + + if(page.equals("logout")) + { + session.setAttribute("email",null); + request.getRequestDispatcher("Author.jsp").forward(request, response); + } + + if(page.equals("edit")) + { + String title = request.getParameter("title"); + String aid = request.getParameter("aid"); + + + request.setAttribute("title", title); + request.setAttribute("aid", aid); + request.getRequestDispatcher("AuthorEdit.jsp").forward(request, response); + } + if (page.equals("hide")) + { + String id = request.getParameter("aid"); + int aid=Integer.parseInt(id); + DB db = new DB(); + try { + db.hideArticle(aid); + } catch (SQLException e) { + e.printStackTrace(); + } + request.getRequestDispatcher("AuthorHome.jsp").forward(request, response); + } + if (page.equals("show")) + { + String id = request.getParameter("aid"); + int aid=Integer.parseInt(id); + DB db = new DB(); + try { + db.showArticle(aid); + } catch (SQLException e) { + e.printStackTrace(); + } + request.getRequestDispatcher("AuthorHome.jsp").forward(request, response); + } + + if(page.equals("edit-form")) + { + String oldtitle = request.getParameter("old-title"); + String title = request.getParameter("title"); + String id = request.getParameter("aid"); + int aid=Integer.parseInt(id); + String highlights = request.getParameter("highlights"); + String abstracts = request.getParameter("abstracts"); + Timestamp time = new Timestamp(System.currentTimeMillis()); + + + DB db = new DB(); + + + if(highlights.length() > 250) + { + //JOptionPane.showMessageDialog(null, "you have typed more than 250 letters in Highlights", "Info", JOptionPane.INFORMATION_MESSAGE); + request.getSession().setAttribute("info","highlight长度不能超过250个字符"); + request.setAttribute("title", oldtitle); + request.getRequestDispatcher("AuthorEdit.jsp").forward(request, response); + } + + else if(abstracts.length() > 999) + { + //JOptionPane.showMessageDialog(null, "you have typed more than 1000 letters in abstract", "Info", JOptionPane.INFORMATION_MESSAGE); + request.getSession().setAttribute("info","abstract长度不能超过999个字符"); + request.setAttribute("title", oldtitle); + request.getRequestDispatcher("AuthorEdit.jsp").forward(request, response); + } + + else + { + + Article a = new Article(); + a.setTitle(title); + a.setHighlights(highlights); + a.setAbstracts(abstracts); + a.setTime(time); + a.setOldtitle(oldtitle); + a.setAid(aid); + + + + try + { + db.updateArticle(a); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + request.getRequestDispatcher("AuthorHome.jsp").forward(request, response); + } +// } else + + } + + if(page.equals("delete")) + { + + String id = request.getParameter("aid"); + int aid=Integer.parseInt(id); + + DB db = new DB(); + + try + { + db.deleteArticle(aid); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + request.getRequestDispatcher("AuthorHome.jsp").forward(request, response); + } + + +//---------------------------------------------------------------------------------------------- +// master function + + if(page.equals("master-home")) + { + request.getRequestDispatcher("Master.jsp").forward(request, response); + } + + if(page.equals("master-articles")) + { + request.getRequestDispatcher("MasterArticles.jsp").forward(request, response); + } + + if(page.equals("master-comments")) + { + request.getRequestDispatcher("Comments.jsp").forward(request, response); + } + + if(page.equals("master-authors")) + { + request.getRequestDispatcher("MasterAuthors.jsp").forward(request, response); + } + + if(page.equals("master-delete")) + { + String id = request.getParameter("aid"); + int aid=-1; + aid=Integer.parseInt(id); + + DB db = new DB(); + + try + { + db.deleteArticle(aid); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + request.getRequestDispatcher("MasterArticles.jsp").forward(request, response); + } + + if(page.equals("master-view-article")) + { + String title = request.getParameter("title"); + + request.setAttribute("title", title); + request.getRequestDispatcher("MasterViewArticle.jsp").forward(request, response); + } + + if(page.equals("master-delete-comments")) + { + String comment = request.getParameter("comment"); + + DB db = new DB(); + + try + { + db.deleteComment(comment); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + request.getRequestDispatcher("Comments.jsp").forward(request, response); + } + + if(page.equals("master-block-author")) + { + String author = request.getParameter("author"); + + DB db = new DB(); + + try + { + db.blockAuthor(author); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + request.getRequestDispatcher("blocklist.jsp").forward(request, response); + } + + if(page.equals("master-release-author")) + { + String author = request.getParameter("author"); + + DB db = new DB(); + + try + { + db.releaseAuthor(author); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + request.getRequestDispatcher("MasterAuthors.jsp").forward(request, response); + } + + if(page.equals("master-dropIp")){ + String ip = request.getParameter("Ip"); + System.out.println("管理员决定把ip为 " + ip + "的用户的痕迹进行消除"); + try { + new DB().deleteIp(ip); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + request.getRequestDispatcher("Master.jsp").forward(request, response); + } + } + +} diff --git a/Controller.java b/Controller.java new file mode 100644 index 0000000..e43fc27 --- /dev/null +++ b/Controller.java @@ -0,0 +1,424 @@ +package com.controller; +import com.service.DB; +import com.service.Get_real_ip; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Timestamp; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class com.controller.Controller + */ +@WebServlet("/com.controller.Controller") +public class Controller extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public Controller() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String page = request.getParameter("page"); + + if(page == null || page.equals("home")) + { + request.getRequestDispatcher("index.jsp").forward(request, response); + } + + else + { + doPost(request, response); + } + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String page = request.getParameter("page"); + + + if(page.equals("like")||page.equals("dislike")) + { + String ip = Get_real_ip.getRemortIP(request); + String title = request.getParameter("title"); + String id = request.getParameter("aid"); + int aid=-1; + aid=Integer.parseInt(id); + int a = -1; + if(page.equals("like")) + { + a=1; + } + else if(page.equals("dislike")) + { + a=0; + } + DB db = new DB(); + boolean status = false; + + try + { + db.check_popular(ip, aid, a,title); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + request.setAttribute("title", title); + request.setAttribute("aid", id); + request.getRequestDispatcher("ViewArticle.jsp").forward(request, response); + + } + + + + if(page.equals("comments_like")||page.equals("comments_dislike")) + { + int a=-1; + String title = request.getParameter("title"); + String ip = Get_real_ip.getRemortIP(request); + int cid = Integer.parseInt(request.getParameter("cid")); + String id= request.getParameter("aid"); + int aid=Integer.parseInt(id); + if(page.equals("comments_like")) + { + a = 1; + } + else if(page.equals("comments_dislike")) + { + a=0; + } + + + DB db = new DB(); + boolean status = false; + + try + { +// status = db.check_comments_popular(ip, id, a); + db.check_comments_popular(ip, cid, a); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + +// if(status) +// { + request.setAttribute("title", title); + request.setAttribute("aid", aid); + request.getRequestDispatcher("ViewArticle.jsp").forward(request, response); +// } +// +// else +// { +// JOptionPane.showMessageDialog(null, "You have already liked the comment.", "Info", JOptionPane.INFORMATION_MESSAGE); + +// request.setAttribute("title", title); +// request.setAttribute("id", id); +// request.getRequestDispatcher("ViewArticle.jsp").forward(request, response); +// } + } + +// if(page.equals("comments_dislike")) +// { +// String title = request.getParameter("title"); +// String ip = Get_real_ip.getRemortIP(request); +// int id = Integer.parseInt(request.getParameter("id")); +// +// int a = 0; +// +// DB db = new DB(); +// boolean status = false; +// +// try +// { +//// status = db.check_comments_popular(ip, id, a); +// db.check_comments_popular(ip, id, a); +// } +// +// catch(SQLException e) +// { +// e.printStackTrace(); +// } +// +//// if(status) +//// { +// request.setAttribute("title", title); +// request.setAttribute("id", id); +// request.getRequestDispatcher("ViewArticle.jsp").forward(request, response); +//// } +//// +//// else +//// { +//// JOptionPane.showMessageDialog(null, "You have already disliked the comment", "Info", JOptionPane.INFORMATION_MESSAGE); +//// +//// request.setAttribute("title", title); +//// request.setAttribute("id", id); +//// request.getRequestDispatcher("ViewArticle.jsp").forward(request, response); +//// } +// +// } + + if(page.equals("administrator")) + { + if (request.getSession().getAttribute("admin_login")!=null) + { + request.getRequestDispatcher("AdministratorHome.jsp").forward(request, response); + + } + else { + request.getRequestDispatcher("Administrator.jsp").forward(request, response); + } + } + if(page.equals("home")) + { + request.getRequestDispatcher("index.jsp").forward(request, response); + } + + if(page.equals("aboutus")) + { + request.getRequestDispatcher("Aboutus.jsp").forward(request, response); + } + + if(page.equals("contact")) + { + request.getRequestDispatcher("Contact.jsp").forward(request, response); + } + + if(page.equals("admin")) + { + + if (request.getSession().getAttribute("admin_login")!=null) + { + request.getRequestDispatcher("AuthorHome.jsp").forward(request, response); + + } + else + { + request.getRequestDispatcher("Author.jsp").forward(request, response); + } + + } + + if(page.equals("select")) + { + String option = request.getParameter("option"); + + if(option.equals("Articles")) + { + request.getRequestDispatcher("Articles.jsp").forward(request, response); + } + + if(option.equals("Comments")) + { + request.getRequestDispatcher("Comments.jsp").forward(request, response); + } + } + + if(page.equals("search")) + { + String search2 = request.getParameter("search2"); + search2=search2.trim(); + if (search2.equals("")) + { + request.getRequestDispatcher("Articles.jsp").forward(request, response); + } + else{ + request.setAttribute("search2", search2); + + request.getRequestDispatcher("Search.jsp").forward(request, response); + } + } + if(page.equals("dropIp")){ + String ip = Get_real_ip.getRemortIP(request); + System.out.println("ip为 " + ip +" 的用户选择了自爆"); + try { + new DB().deleteIp(ip); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + request.getRequestDispatcher("Aboutus.jsp").forward(request, response); + } + + if(page.equals("subject")) + { + String subject = request.getParameter("id"); + String psid = request.getParameter("psid"); + + + request.setAttribute("subject", subject); + request.setAttribute("psid", psid); + + request.getRequestDispatcher("NewFile.jsp").forward(request, response); +// response.sendRedirect("NewFile.jsp"); + } + + if(page.equals("post-article")) + { + String subject = request.getParameter("subject"); + String psid = request.getParameter("psid"); + String email = request.getParameter("email"); + String authorName = request.getParameter("authorName"); + + + boolean status = false; + DB db = new DB(); + + try + { + status = db.checkblockauthor(email); + } + + catch(SQLException e) + { + e.printStackTrace(); + } + + if(status) + { + //JOptionPane.showMessageDialog(null, "Sorry you have been blcoked, please contact Author", "Info", JOptionPane.INFORMATION_MESSAGE); + + request.setAttribute("subject", subject); + request.setAttribute("psid", psid); + request.getRequestDispatcher("NewFile.jsp").forward(request, response); + } + + else + { + request.setAttribute("subject", subject); + request.setAttribute("email", email); + request.setAttribute("psid", psid); + request.setAttribute("authorName", authorName); + request.getRequestDispatcher("PostArticle.jsp").forward(request, response); + } + + } + + if(page.equals("view-article")) + { + String title = request.getParameter("title"); + String aid = request.getParameter("id"); + String ip = Get_real_ip.getRemortIP(request); + DB db = new DB(); + try { + db.addVisit(aid,ip,title); + } catch (SQLException e) { + e.printStackTrace(); + } + request.setAttribute("aid",aid); + request.setAttribute("title", title); + request.getRequestDispatcher("ViewArticle.jsp").forward(request, response); + } + + if(page.equals("admin-view-article")) + { + String title = request.getParameter("title"); + + request.setAttribute("title", title); + request.getRequestDispatcher("AuthorViewArticle.jsp").forward(request, response); + } + + if(page.equals("comment-post")) + { + int aid=-1; + String id = request.getParameter("aid"); + if (id!=null&&!id.equals("")) + { + aid=Integer.parseInt(id); + } + System.out.println("插入评论表的aid="+aid); + String comment = request.getParameter("comment"); + String title = request.getParameter("title"); + Timestamp time = new Timestamp(System.currentTimeMillis()); + + String comment2 = comment.toLowerCase(); + if(comment.length()>10000) + { + request.setAttribute("title", title); + request.setAttribute("msg","The length of comment can not exceed 10000 characters!"); + } + else if (comment2.contains("fuck") || comment2.contains("motherfucker") || comment2.contains("nigga") || comment2.contains("bitch") + || comment2.contains("idiot") || comment2.contains("stupid") || comment2.contains("dick") || comment2.contains("boobs") || comment2.contains("pussy") || comment2.contains("suck")) { +// System.out.println("illegal"); + + request.setAttribute("title", title); + request.setAttribute("msg", "using improper words, please use proper words"); + + } else { + + + try { + String wzf = "wzf"; + String password = "wzf"; + String url = "jdbc:mysql://121.4.94.30:3306/oo?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8"; + String driver = "com.mysql.jdbc.Driver"; + Connection con; + + Class.forName(driver); + + String sql = "insert into comments (title, aid, comment, time) values (?,?,?,?)"; + + con = DriverManager.getConnection(url, wzf, password); + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, title); + ps.setInt(2, aid); + ps.setString(3, comment); + ps.setTimestamp(4, time); + + ps.executeUpdate(); + + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + +// System.out.println(email); +// System.out.println(comment); +// System.out.println(title); +// System.out.println(time); + + request.setAttribute("title", title); + request.setAttribute("aid", aid); + + + } + request.getRequestDispatcher("ViewArticle.jsp").forward(request, response); + + } + + if(page.equals("authorarticle")) + { + String author = request.getParameter("author"); + + request.setAttribute("author", author); + request.getRequestDispatcher("AuthorArticle.jsp").forward(request, response); + } + + } + +} diff --git a/DB.java b/DB.java new file mode 100644 index 0000000..7de1140 --- /dev/null +++ b/DB.java @@ -0,0 +1,664 @@ +package com.service; + +import com.javaBean.*; + +import java.sql.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DB { + + public String wzf = "wzf"; + public String url = "jdbc:mysql://121.4.94.30:3306/oo?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8"; + public String password = "wzf"; + public String Driver = "com.mysql.jdbc.Driver"; + public Connection con; + + public void connect() throws SQLException + { + try + { + Class.forName(Driver); + + con = DriverManager.getConnection(url, wzf, password); + + } + + catch(ClassNotFoundException e) + { + e.printStackTrace(); + } + + } + + public void close() throws SQLException + { + con.close(); + } + + public void updateArticle(Article a) throws SQLException + { + connect(); + + String sql = "update article set title=?, highlight=?, abstracts=?, time=? where title=? and aid=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, a.getTitle()); + ps.setString(2, a.getHighlights()); + ps.setString(3, a.getAbstracts()); + ps.setTimestamp(4, a.getTime()); + ps.setString(5, a.getOldtitle()); + ps.setInt(6, a.getAid()); + ps.executeUpdate(); + + close(); + } + public void updateSubject(Subject s) throws SQLException + { + connect(); + + String sql = "update subject set subject=?, sdate=? where subject=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, s.getSubject()); + ps.setTimestamp(2,s.sdate); + ps.setString(3, s.getOldsubject()); + + ps.executeUpdate(); + + close(); + } + public void showArticle(int aid) throws SQLException + { + connect(); + String sql="update article set hide=? where aid=?"; + PreparedStatement ps = con.prepareStatement(sql); + ps.setString(1,"No"); + ps.setInt(2,aid); + ps.executeUpdate(); + close(); + + + + } + public void hideArticle(int aid) throws SQLException + { + connect(); + String sql="update article set hide=? where aid=?"; + PreparedStatement ps = con.prepareStatement(sql); + ps.setString(1,"Yes"); + ps.setInt(2,aid); + ps.executeUpdate(); + close(); + + + + } + + public void deleteArticle(int aid) throws SQLException + { + connect(); + + String sql = "delete from article where aid=?"; + + PreparedStatement ps = con.prepareStatement(sql); + ps.setInt(1, aid); + ps.executeUpdate(); + String sql2 = "delete from comments where aid=?"; + + PreparedStatement ps2 = con.prepareStatement(sql2); + ps2.setInt(1, aid); + ps2.executeUpdate(); + String sql3 = "delete from comments where aid=?"; + + PreparedStatement ps3 = con.prepareStatement(sql3); + ps3.setInt(1, aid); + ps3.executeUpdate(); + close(); + + } + + public void deleteSubject(int sid) throws SQLException + { + connect(); + + String sql = "delete from subject where sid=? or parentsid=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setInt(1, sid); + ps.setInt(2, sid); + ps.executeUpdate(); + + close(); + + } + + + public void deleteComment(String comment) throws SQLException + { + connect(); + + String sql = "delete from comments where comment=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, comment); + ps.executeUpdate(); + + close(); + + } + + public void addAuthor(Author a) throws SQLException + { + connect(); + + String sql = "insert into author(email,password) values(?,?)"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, a.getEmail()); + ps.setString(2, a.getPassword()); + ps.executeUpdate(); + + close(); + + } + public void addSubject(Subject a) throws SQLException + { + connect(); + + String sql = "insert into subject(sid,subject,sdate,parentsid) values(?,?,?,?)"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setInt(1,0); + ps.setString(2, a.getSubject()); + ps.setTimestamp(3, a.getSdate()); + int parentsid=0; + if (a.parentsid!=0) + { + parentsid=a.getParentsid(); + + + } + ps.setInt(4,parentsid); + ps.executeUpdate(); + + close(); + + } + + public boolean checkAuthor(Author a) throws SQLException + { + connect(); + + boolean result = false; + int i = 0; + + String sql = "select * from author where email=? and password=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, a.getEmail()); + ps.setString(2, a.getPassword()); + + ResultSet rs = ps.executeQuery(); + + while(rs.next()) + { + i = 1; + result= true; + } + + close(); + + return result; + } + public boolean checkAdministrator(Administrator a) throws SQLException + { + connect(); + + boolean result = false; + int i = 0; + + String sql = "select * from administrator where email=? and password=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, a.getEmail()); + ps.setString(2, a.getPassword()); + + ResultSet rs = ps.executeQuery(); + + if(rs.next()) + { + + result= true; + } + + close(); + + return result; + } + + public boolean checkblockauthor(String email) throws SQLException + { + connect(); + + boolean result = false; + int i = 0; + + + String sql = "select * from block_author where email=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, email); + + + ResultSet rs = ps.executeQuery(); + + while(rs.next()) + { + i = 1; + result= true; + } + + close(); + + return result; + } +public void addVisit(String id,String ip,String title) throws SQLException + { + int aid=-1; + if (id!=null&&!id.equals("")) + { + aid=Integer.parseInt(id); + + } + + connect(); + String sql0="select * from visit where ip=? and aid=?"; + PreparedStatement ps0 = con.prepareStatement(sql0); + ps0.setString(1,ip); + ps0.setInt(2,aid); + ResultSet resultSet = ps0.executeQuery(); + if (!resultSet.next()&&aid!=-1) + { + Timestamp time = new Timestamp(System.currentTimeMillis()); + String sql = "insert into visit(vid,aid,ip,vdate) values (?,?,?,?)"; + PreparedStatement ps = con.prepareStatement(sql); + ps.setInt(1,0); + ps.setInt(2,aid); + ps.setString(3,ip); + ps.setTimestamp(4,time); + ps.executeUpdate(); + } + close(); + + + } + + public void blockAuthor(String author) throws SQLException + { + connect(); + + String sql = "insert into block_author(email) values(?)"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, author); + ps.executeUpdate(); + + close(); + + } + + public void releaseAuthor(String author) throws SQLException + { + connect(); + + String sql = "delete from block_author where email=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, author); + ps.executeUpdate(); + + close(); + + } + + + public boolean checktitle(String title) throws SQLException + { + connect(); + + boolean result = false; + int i = 0; + + String sql = "select * from article a , subject s where a.sid=s.sid and title=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, title); + + + ResultSet rs = ps.executeQuery(); + + while(rs.next()) + { + i = 1; + result= true; + break; + } + + close(); + + return result; + } + public boolean checksubject(String subject) throws SQLException + { + connect(); + + boolean result = false; +// int i = 0; + + String sql = "select * from subject where subject=?"; + + PreparedStatement ps = con.prepareStatement(sql); + + ps.setString(1, subject); + + + ResultSet rs = ps.executeQuery(); + + while(rs.next()) + { +// i = 1; + result= true; + break; + } + + close(); + + return result; + } + + + + // public boolean check_popular(String ip, String title, int a) throws SQLException +// { + public void check_popular(String ip, int aid, int a,String title) throws SQLException + { + connect(); + int i = 0; + String sql = "insert into love_article(ip, aid, prefer,title) values(?, ?, ?,?)"; + String sql2 = "select * from love_article where ip=? and aid=?"; + String sql3 = "update love_article set prefer=? where ip=? and aid=?"; + + PreparedStatement ps2 = con.prepareStatement(sql2); + ps2.setString(1, ip); + ps2.setInt(2, aid); + + ResultSet rs = ps2.executeQuery(); + + if (rs.next()) + { + i = 1; + + } + if(i==1) + { + PreparedStatement ps3 = con.prepareStatement(sql3); + ps3.setInt(1, a); + ps3.setString(2, ip); + ps3.setInt(3, aid); + ps3.executeUpdate(); + } + + else if(i==0) + { + PreparedStatement ps = con.prepareStatement(sql); + ps.setString(1, ip); + ps.setInt(2, aid); + ps.setInt(3, a); + ps.setString(4,title); + ps.executeUpdate(); + } + + + close(); + +// return result; + } + + /* + + This function checks whether the user with the specific 'ip', has liked/disliked the comment + with the specific 'id'. + 'a' is a flag to determine whether the required operation is like or dislike, where a = 0, if + the required operation is dislike, and a = 1 if it's like. + + */ +// public boolean check_comments_popular(String ip, int id, int a) throws SQLException +// { + public void check_comments_popular(String ip, int id, int a) throws SQLException + { + connect(); + +// boolean result = false; + int i = 0; + + + + String sql = "insert into love_comment(ip, cid, prefer) values(?, ?, ?)"; + String sql2 = "select * from love_comment where ip=? and cid=?"; + String sql3 = "update love_comment set prefer=? where ip=? and cid=?"; + + PreparedStatement ps2 = con.prepareStatement(sql2); + ps2.setString(1, ip); + ps2.setInt(2, id); + + ResultSet rs = ps2.executeQuery(); + + if(rs.next()) + { + i = 1; + } + + if(i==1) + { + PreparedStatement ps3 = con.prepareStatement(sql3); + ps3.setInt(1, a); + ps3.setString(2, ip); + ps3.setInt(3, id); + ps3.executeUpdate(); +// result = false; + } + + else if(i==0) + { + PreparedStatement ps = con.prepareStatement(sql); + ps.setString(1, ip); + ps.setInt(2, id); + ps.setInt(3, a); + ps.executeUpdate(); +// result = true; + } + + + close(); + +// return result; + } + public Map selectAIDTitle() throws SQLException { + Map map=new HashMap(); + connect(); + String sql="select aid,title from article where hide='No'"; + PreparedStatement ps = con.prepareStatement(sql); + ResultSet res = ps.executeQuery(); + while (res.next()){ + map.put(res.getInt("aid"),res.getString("title")); + } + close(); + return map; + } + public Popularity getPopularity(Integer aid,String title) throws SQLException { + Integer commentNum=0; + Integer likesNum=0; + Integer dislikeNum=0; + Integer visitNum=0; + Double dayDis=0.0; + Timestamp time=new Timestamp(0); + Double popularity=0.0; + connect(); + String sql; + PreparedStatement ps; + ResultSet res; + sql="select count(*) from comments where aid=?"; + ps = con.prepareStatement(sql); + ps.setInt(1,aid); + res = ps.executeQuery(); + + if (res.next()){ + commentNum=res.getInt(1); + + } + sql="select count(*) from love_article where aid=? and prefer=?"; + ps = con.prepareStatement(sql); + ps.setInt(1,aid); + ps.setInt(2,1); + res = ps.executeQuery(); + if (res.next()){ + likesNum=res.getInt(1); + + } + sql="select count(*) from love_article where aid=? and prefer=?"; + ps = con.prepareStatement(sql); + ps.setInt(1,aid); + ps.setInt(2,0); + res = ps.executeQuery(); + if (res.next()){ + dislikeNum=res.getInt(1); + + } + sql="select count(*) from visit where aid=?"; + ps = con.prepareStatement(sql); + ps.setInt(1,aid); + res = ps.executeQuery(); + if (res.next()){ + visitNum=res.getInt(1); + + } + sql="select time from article where aid=?"; + ps = con.prepareStatement(sql); + ps.setInt(1,aid); + res = ps.executeQuery(); + if (res.next()){ + time=res.getTimestamp("time"); + + } + dayDis=(System.currentTimeMillis()-time.getTime())/(1000*3600*24.0)*(-1); + popularity=(4*commentNum+3*likesNum+2*dislikeNum+visitNum)*Math.exp(dayDis/100.0); + Popularity pop=new Popularity(); + pop.setCommentNum(commentNum); + pop.setDayDis(dayDis); + pop.setIntDayDis(dayDis.intValue()*(-1)); + pop.setLikesNum(likesNum); + pop.setDislikeNum(dislikeNum); + pop.setVisitNum(visitNum); + pop.setAid(aid); + pop.setTitle(title); + pop.setPopularity(popularity); + pop.setIntPop(popularity.intValue()); + + close(); + return pop; + + + + + + + + + + + } + + private boolean deleteCommentByIp(String id) throws SQLException { + String sql; + PreparedStatement preparedStatement; + + sql = "delete from love_comment where cid = ?"; + preparedStatement = con.prepareStatement(sql); + preparedStatement.setString(1,id); + preparedStatement.executeUpdate(); + + sql = "delete from comments where id = ?"; + preparedStatement = con.prepareStatement(sql); + preparedStatement.setString(1, id); + preparedStatement.executeUpdate(); + + return true; + } + + private boolean deleteArticleByIp(String id) throws SQLException { + String sql; + PreparedStatement preparedStatement; + ResultSet resultSet; + + sql = "select * from comments where aid = ?"; + preparedStatement = con.prepareStatement(sql); + preparedStatement.setString(1,id); + + resultSet = preparedStatement.executeQuery(); + + while(resultSet.next()){ + String cid = resultSet.getString("id"); + deleteCommentByIp(cid); + } + + sql = "delete from love_article where aid = ?"; + preparedStatement = con.prepareStatement(sql); + preparedStatement.setString(1,id); + preparedStatement.executeUpdate(); + + sql = "delete from article where aid = ?"; + PreparedStatement preparedStatement2 = con.prepareStatement(sql); + preparedStatement2.setString(1,id); + preparedStatement2.executeUpdate(); + + return true; + } + + public boolean deleteIp(String ip) throws SQLException { + connect(); + + String sql; + PreparedStatement preparedStatement; + ResultSet resultSet; + + sql = "select * from article where ip = ?"; + preparedStatement = con.prepareStatement(sql); + preparedStatement.setString(1,ip); + resultSet = preparedStatement.executeQuery(); + + while(resultSet.next()){ + String aid = resultSet.getString("aid"); + deleteArticleByIp(aid); + } + + close(); + return true; + } + + +} diff --git a/Master.jsp b/Master.jsp new file mode 100644 index 0000000..5825902 --- /dev/null +++ b/Master.jsp @@ -0,0 +1,69 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Master Author + + + + + + + +
+

Welcome Author

+ +
+ +
+ + + + + + + + \ No newline at end of file diff --git "a/\346\225\210\346\236\234\346\274\224\347\244\272.mp4" "b/\346\225\210\346\236\234\346\274\224\347\244\272.mp4" new file mode 100644 index 0000000..ed77f06 Binary files /dev/null and "b/\346\225\210\346\236\234\346\274\224\347\244\272.mp4" differ