论文查重系统
首先,利用建民老大给的python代码爬取论文:
`import requests
import pymysql
from bs4 import BeautifulSoup
db = pymysql.connect(host="localhost", user="root", password="20204112", database="student",charset="utf8")
cursor = db.cursor()
headers={
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
}
url="https://openaccess.thecvf.com/WACV2022"
html=requests.get(url)
soup=BeautifulSoup(html.content,'html.parser')
soup.a.contents=='pdf'
pdfs=soup.findAll(name="a",text="pdf")
lis = []
jianjie=""
for i,pdf in enumerate(pdfs):
pdf_name=pdf["href"].split('/')[-1]
name=pdf_name.split('.')[0].replace("_CVPR_2022_paper","")
link="http://openaccess.thecvf.com/content_CVPR_2022/html/"+name+"CVPR_2022_paper.html"
url1=link
html1 = requests.get(url1)
soup1 = BeautifulSoup(html1.content, 'html.parser')
weizhi = soup1.find('div', attrs={'id':'abstract'})
if weizhi:
jianjie =weizhi.get_text();
print("这是第"+str(i)+"条数据")
keyword = str(name).split('')
keywords = ''
for k in range(len(keyword)):
if (k == 0):
keywords += keyword[k]
else:
keywords += ',' + keyword[k]
info = {}
info['title'] = name
info['link'] =link
info['abstract']=jianjie
info['keywords']=keywords
lis.append(info)
cursor = db.cursor()
for i in range(len(lis)):
cols = ", ".join('{}
'.format(k) for k in lis[i].keys())
print(cols) # 'name
, age
'
val_cols = ', '.join('%({})s'.format(k) for k in lis[i].keys()) print(val_cols) # '%(name)s, %(age)s' sql = "insert into lunwen(%s) values(%s)" res_sql = sql % (cols, val_cols) print(res_sql) cursor.execute(res_sql, lis[i]) # 将字典a传入 db.commit() num=1 print(num) print("ok")
`
然后就是页面的设计:
add.jsp
`<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
%> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %>
`
alter.jsp
`<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
%> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %>
`
echat.jsp
`<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
%> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %>
`
result.jsp
`<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
%> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %>
<c:forEach var="u" items="${list}"> <table align="center" valign="middle" border=1> <tr><td class="td">id: </td> <td class="td"> ${u.id } </td></tr> <tr><td class="td">关键词为: </td> <td class="td"> ${u.keywords } </td></tr> <tr><td class="td">标题为: </td> <td class="td"> ${u.title } </td></tr> <tr><td class="td">链接为: </td> <td class="td"> ${u.link } </td></tr> </table> <tr><td class="td"></td><td class="td"></td></tr> <form action = "Servlet?method=delete" method="post" > <input class="input" type="hidden" name="delete" id ="delete" value ="${u.id}"> <input class="input" type="submit" value = "删除"> </form> <form action = "Servlet?method=alter" method="post" > <input type="hidden" name="alter" id ="later" value ="${u.id}"> <input class="input" type="submit" value = "修改"></td> </form> </c:forEach> </div> >
`
java代码
baen.java
`package Bean;
public class bean {
private String id;
private String title;
private String keywords;
private String link;
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
}
dao.java
package Dao;
import Bean.bean;
import DBUtil.DBUtil;
import java.util.ArrayList;
import java.util.List;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class Dao {
public List<bean> searchById(String id) { List<bean> list = new ArrayList<bean>(); try { Connection conn = DBUtil.getConn(); Statement state = null; String sql = "select * from lunwen where id='" + id + "'"; PreparedStatement pstmt = conn.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { bean lu = new bean(); lu.setId(rs.getString("id")); lu.setKeywords(rs.getString("keywords")); lu.setTitle(rs.getString("title")); lu.setLink(rs.getString("link")); System.out.println(lu.getId()); list.add(lu); } rs.close(); pstmt.close(); conn.close(); } catch (SQLException e) { System.out.println("发生错误"); e.printStackTrace(); } return list; } public List<bean> search(String id, String title, String keywords) { List<bean> list = new ArrayList<bean>(); try { Connection conn = DBUtil.getConn(); Statement state = null; String sql = "select * from lunwen where id like '%" + id + "%' and title like '%" + title + "%' and keywords like '%" + keywords + "%'"; PreparedStatement pstmt = conn.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { bean lu = new bean(); lu.setId(rs.getString("id")); lu.setKeywords(rs.getString("keywords")); lu.setTitle(rs.getString("title")); lu.setLink(rs.getString("link")); list.add(lu); } rs.close(); pstmt.close(); conn.close(); } catch (SQLException e) { System.out.println("发生错误"); e.printStackTrace(); } return list; } public boolean add(bean bean) { Connection conn = DBUtil.getConn(); PreparedStatement pstmt = null; boolean f = false; int a = 0; try { String sql = "insert into lunwen(title,link) value(?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, bean.getTitle()); pstmt.setString(2, bean.getLink()); a = pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(pstmt, conn); } if (a > 0) f = true; return f; } public boolean delete(String id) { boolean flag = false; Connection conn = DBUtil.getConn(); Statement state = null; try { String sql = "delete from lunwen where id = '" + id + "'"; PreparedStatement pstmt = conn.prepareStatement(sql); int i = pstmt.executeUpdate(); pstmt.close(); conn.close(); if (i > 0) flag = true; } catch (SQLException e) { System.out.println("删除失败!"); e.printStackTrace(); } return flag; } // 修改车站信息 public boolean alter(bean bean, String id) { String sql = "update title set tltle='" + bean.getTitle() + "', link='" + bean.getLink() + "' where id='" + id + "'"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); System.out.println("修改成功"); a = state.executeUpdate(sql); System.out.println(a); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } System.out.println(f); return f; } public void xiugai(String id, String title, String link) { Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; int flag = 0; System.out.printf(id + title + link); try { String sql = "update lunwen set title='" + title + "',link ='" + link + "' where id='" + id + "'"; state = conn.createStatement(); int count = state.executeUpdate(sql); if (count > 0) { System.out.println("插入成功"); } else { System.out.println("插入失败"); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } }
}
DBUtil.java
package DBUtil;
import java.sql.*;
public class DBUtil {
public static String db_url = "jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT"; public static String db_user = "root"; public static String db_password = "20204112";
// ݿ
public static Connection getConn () {
Connection conn = null;
try { Class.forName("com.mysql.cj.jdbc.Driver");// conn = DriverManager.getConnection(db_url,db_user, db_password); } catch (Exception e) { e.printStackTrace(); } return conn; } // ر public static void close (PreparedStatement preparedState, Connection conn) { if (preparedState != null) { try { preparedState.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, PreparedStatement preparedState, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (preparedState != null) { try { preparedState.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } // Ƿ ӳɹ public static void main(String[] args) throws SQLException { Connection conn = getConn(); PreparedStatement preparedStatement = null; ResultSet rs = null; String sql ="select * from lunwen";// ݿ preparedStatement = conn.prepareStatement(sql); rs = preparedStatement.executeQuery(); if(rs.next()){ System.out.println(" Ѿ ȡ ɹ "); } else{ System.out.println(" ȡʧ "); } }
}
servlet.java
package Servlet;
import java.io.IOException;
import java.util.List;
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 Bean.bean;
import Dao.Dao;
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Dao dao = new Dao(); protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String method = req.getParameter("method"); if ("searchbyid".equals(method)) { searchById(req, resp); } else if ("search".equals(method)) { search(req, resp); } else if ("add".equals(method)) { add(req, resp); } else if ("delete".equals(method)) { delete(req, resp); } else if ("alter".equals(method)) { alter(req, resp); } else if ("alter2".equals(method)) { alter2(req, resp); } } public Servlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().append("Served at: ").append(request.getContextPath()); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } private void searchById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // System.out.println(req.getParameter("title")); req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8"); Dao dao = new Dao(); List<bean> list = dao.searchById((String) req.getParameter("id")); System.out.println("****************" + (String) req.getParameter("id")); req.setAttribute("list", list); req.getRequestDispatcher("result.jsp").forward(req, resp);// 转到指定页面 System.out.println("成功运行"); } private void search(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8"); Dao dao = new Dao(); String id = (String) req.getParameter("id"); String title = (String) req.getParameter("title"); String keywords = (String) req.getParameter("keywords"); System.out.println(id + title + keywords); List<bean> list = dao.search(id, title, keywords); req.setAttribute("list", list); req.getRequestDispatcher("result.jsp").forward(req, resp);// 转到指定页面 System.out.println("跳转完成"); } private void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8"); String title = req.getParameter("title"); String link = req.getParameter("link"); bean bean = new bean(); bean.setLink(link); bean.setTitle(title); if (dao.add(bean)) { req.setAttribute("bean", bean); req.setAttribute("message", "添加成功"); req.getRequestDispatcher("index.jsp").forward(req, resp); } else { req.setAttribute("message", "添加失败请重试"); req.getRequestDispatcher("add.jsp").forward(req, resp); } } protected void delete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); Dao sd = new Dao(); String id = req.getParameter("delete"); if (dao.delete(id)) { req.setAttribute("message", "删除成功"); req.getRequestDispatcher("index.jsp").forward(req, resp); } else { req.setAttribute("message", "失败"); req.getRequestDispatcher("result.jsp").forward(req, resp); } } protected void alter(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); Dao dao = new Dao(); String id = (String) req.getParameter("alter"); List<bean> list = dao.searchById(id); req.setAttribute("list", list); req.getRequestDispatcher("alter.jsp").forward(req, resp);// 转到指定页面 } private void alter2(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); Dao dao = new Dao(); String id = req.getParameter("id"); String title = req.getParameter("title"); String link = req.getParameter("link"); dao.xiugai(id, title, link); req.getRequestDispatcher("alter.jsp").forward(req, resp); }
}
`
本文作者:信2005-2刘海涛
本文链接:https://www.cnblogs.com/lht020321/p/16316805.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步