From 31b41033b6a1d0d5255ded4da79c0626f9a40ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E6=A2=93=E9=91=AB?= <1813169067@qq.com> Date: Tue, 6 Jun 2023 22:57:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20220605.md" | 384 ++++++++++++++++++ 1 file changed, 384 insertions(+) create mode 100644 "27\351\222\237\346\242\223\351\221\253/20220605.md" diff --git "a/27\351\222\237\346\242\223\351\221\253/20220605.md" "b/27\351\222\237\346\242\223\351\221\253/20220605.md" new file mode 100644 index 0000000..91f7dcd --- /dev/null +++ "b/27\351\222\237\346\242\223\351\221\253/20220605.md" @@ -0,0 +1,384 @@ +package bean; + +public class attence { + private int id ; + private String time; + private int type; + private int sid; + private String sname; + + public attence() { + } + + public attence(int id, String time, int type, int sid, String sname) { + this.id = id; + this.time = time; + this.type = type; + this.sid = sid; + this.sname = sname; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public int getSid() { + return sid; + } + + public void setSid(int sid) { + this.sid = sid; + } + + public String getSname() { + return sname; + } + + public void setSname(String sname) { + this.sname = sname; + } +} +package bean; + +public class student { + private int sid; + private String sname; + + public student() { + } + + public student(int sid, String sname) { + this.sid = sid; + this.sname = sname; + } + + public int getSid() { + return sid; + } + + public void setSid(int sid) { + this.sid = sid; + } + + public String getSname() { + return sname; + } + + public void setSname(String sname) { + this.sname = sname; + } +} +package servlet; + +import bean.attence; +import util.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +@WebServlet("/list") +public class list extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf-8"); + ArrayList list = new ArrayList(); + String sql = "select * from attence a ,student s where s.sid=a.sid"; + Connection conn = null; + PreparedStatement prs = null; + ResultSet rs = null; + try { + conn = DBUtil.getConn(); + prs = conn.prepareStatement(sql); + rs = prs.executeQuery(); + while (rs.next()) { + int aid = rs.getInt(1); + String time = rs.getString(2); + int type = rs.getInt(3); + int sid = rs.getInt(5); + String sname = rs.getString(6); + list.add(new attence(aid, time, type, sid, sname)); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + DBUtil.close(conn, prs, rs); + } + request.setAttribute("list",list); + request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} + +package servlet; + +import bean.student; +import util.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +@WebServlet(name = "add", value = "/add") +public class add extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf-8"); + ArrayList list = new ArrayList(); + String sql = "select * from student"; + Connection conn = null; + PreparedStatement prs = null; + ResultSet rs = null; + try { + conn = DBUtil.getConn(); + prs = conn.prepareStatement(sql); + rs = prs.executeQuery(); + while (rs.next()) { + int sid = rs.getInt(1); + String name = rs.getString(2); + list.add(new student(sid,name)); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + DBUtil.close(conn, prs, rs); + } + request.setAttribute("list",list); + request.getRequestDispatcher("/WEB-INF/add.jsp").forward(request,response); + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} + +package servlet; + +import util.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +@WebServlet(name = "save", value = "/save") +public class save extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf-8"); + int name = Integer.parseInt(request.getParameter("name")); + String time = request.getParameter("time"); + String type = request.getParameter("type"); + int i=0; + System.out.println(type); + if ("yd".equals(type)) { + i = 1; + } else if ("cd".equals(type)) { + i = 2; + } else if ("kk".equals(type)) { + i=3; + } + System.out.println(i); + int a; + String sql = "insert into attence values (?,?,?,?)"; + Connection conn = null; + PreparedStatement prs = null; + try { + conn = DBUtil.getConn(); + prs = conn.prepareStatement(sql); + prs.setInt(1, 0); + prs.setString(2, time); + prs.setInt(3,i); + prs.setInt(4, name); + a = prs.executeUpdate(); + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + DBUtil.close(conn, prs, null); + } + if (a > 0) { + request.setAttribute("smg", "成功添加"); + request.getRequestDispatcher("/WEB-INF/smg.jsp").forward(request, response); + } else { + request.setAttribute("smg", "添加失败"); + request.getRequestDispatcher("/WEB-INF/smg.jsp").forward(request, response); + } + + } +} +package util; + +import java.sql.*; + +public class DBUtil { + private static final String url="jdbc:mysql:///attdb?characterEncoding=utf8"; + private static final String user ="root"; + private static final String pwb ="root"; + + static { + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + public static Connection getConn () throws SQLException { + Connection conn = DriverManager.getConnection(url, user, pwb); + return conn; + } + public static void close(Connection conn, PreparedStatement prs, ResultSet rs){ + try { + if (rs!=null){ + rs.close(); + } + if (prs!=null){ + prs.close(); + } + if (conn!=null){ + conn.close(); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } +} +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-05 + Time: 09:01 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + +添加 + + + + + + + + + + + +
考勤编号学生编号学生姓名出勤时间出勤状态
${bar.id}${bar.sid}${bar.sname}${bar.time}${bar.type==1 ? "已到" :bar.type==2?"迟到": bar.type==3 ?"旷课":"没来"}
+ + + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-05 + Time: 09:21 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + +

学生考勤系统

+
+ + + + + + + + + + + + + + + + + +
学生姓名 + +
考勤时间
考勤状况已到: + 迟到: + 旷课:
+
+ + + +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-05 + Time: 10:48 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + +${smg} +
+返回 + + \ No newline at end of file -- Gitee