From 2135cc6e5ae15d6a0cc5c61b37088b1203723789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=A9=E4=B8=9C?= <3187628460@qq.com> Date: Tue, 6 Jun 2023 22:22:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E8=80=83=E5=8B=A4=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...03\345\213\244\347\263\273\347\273\237.md" | 361 ++++++++++++++++++ 1 file changed, 361 insertions(+) create mode 100644 "23 \351\273\204\346\265\251\344\270\234/20230605 \345\255\246\347\224\237\350\200\203\345\213\244\347\263\273\347\273\237.md" diff --git "a/23 \351\273\204\346\265\251\344\270\234/20230605 \345\255\246\347\224\237\350\200\203\345\213\244\347\263\273\347\273\237.md" "b/23 \351\273\204\346\265\251\344\270\234/20230605 \345\255\246\347\224\237\350\200\203\345\213\244\347\263\273\347\273\237.md" new file mode 100644 index 0000000..3cf63b4 --- /dev/null +++ "b/23 \351\273\204\346\265\251\344\270\234/20230605 \345\255\246\347\224\237\350\200\203\345\213\244\347\263\273\347\273\237.md" @@ -0,0 +1,361 @@ +```java +// 学生信息封装类 + 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 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; + } +} + +``` + +```java +// 表格信息 +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 { + + } +} + +``` + +```jsp +//表格网页 +<%@ 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 ?"旷课":"没来"}
+ + + +``` + +```java +// 添加信息读取 +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 { + + } +} +``` + +```jsp +//添加表单 +<%@ 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 + + +

学生考勤系统

+
+ + + + + + + + + + + + + + + + + +
学生姓名 + +
考勤时间
考勤状况已到: + 迟到: + 旷课:
+
+ + + +``` + +```java +//添加处理反馈 +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); + } + + } +} +``` + +```java +//网页信息反馈 +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + +${smg} +
+返回 + + +``` + -- Gitee