当前位置: 首页 > news >正文

javaweb入门版学生信息管理系统-增删改查+JSP+Jstl+El

dao


public class StudentDao {QueryRunner queryRunner = QueryRunnerUtils.getQueryRunner();//查询全部学生信息public List<Student> selectStudent(){String sql = "select * from tb_student";List<Student> students = null;try {students =queryRunner.query(sql, new BeanListHandler<>(Student.class));} catch (SQLException e) {e.printStackTrace();}return students;}//根据学生姓名查询信息public List<Student> selectName(String username){String sql = "select * from tb_student where sname = ? ";List<Student> list = null;try {list = queryRunner.query(sql, new BeanListHandler<>(Student.class), username);} catch (SQLException e) {e.printStackTrace();}return list;}//添加一条学生信息public int insert(String username,int age,String sex,String email){int rows = 0;String sql = "insert into tb_student(sname,sage,ssex,semail) values(?,?,?,?)";try {rows = queryRunner.update(sql, username, age, sex, email);} catch (SQLException e) {e.printStackTrace();}return rows;}//删除一条学生信息public int delete(int id){String sql = "delete from tb_student where sid = ?";int rows = 0;try {rows = queryRunner.update(sql, id);} catch (SQLException e) {e.printStackTrace();}return rows;}//修改学生信息public int update(int id,String username,int age,String sex,String email){String sql = "update tb_student set sname=?,sage=?,ssex=?,semail=? where sid = ?";int rows = 0;try {rows = queryRunner.update(sql, username, age, sex, email, id);} catch (SQLException e) {e.printStackTrace();}return rows;}
}

 

<%@ page import="com.etime.entity.Student" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head><title>学生信息</title>
</head>
<body>
<div align="center"><h1>学生信息</h1><%--添加学生--%><a href="insertStudent.jsp"><button>新增</button></a><%--显示全部学生信息--%><a href="StudentServlet?type=student"><button>查看全部</button></a><%--搜索学生信息--%><form action="StudentServlet" method="get"><input type="hidden" name="type" value="selectName"><input type="text"  name="selectText" placeholder="请输入要查询的人的姓名"><input type="submit" value="搜索"></form><%--展示学生信息--%><table border="2" cellpadding="0" cellspacing="0" align="center"><tr></tr><tr><th>学号</th><th>姓名</th><th>年龄</th><th>性别</th><th>邮箱</th><th>操作</th></tr><%-- 优化版--%><c:forEach var="stu" items="${list}"><tr><td>${stu.sid}</td><td>${stu.sname}</td><td>${stu.sage}</td><td>${stu.ssex}</td><td>${stu.semail}</td><td><a href="updateStudent.jsp?id=${stu.sid}&name=${stu.sname}&age=${stu.sage}&sex=${stu.ssex}&email=${stu.semail}"><input type="button" value="修改"></a><a href="StudentServlet?type=delete&id=${stu.sid}"><input type="button" value="删除"></a></td></tr></c:forEach></table><a href="PaginationServlet?type=first"><button>首页</button></a><a href="">上一页</a>1/12<a href="">下一页</a><a href="PaginationServlet?type=last">尾页</a>
</div>
</body>
</html>

 servlet

package com.etime.servlet;import com.etime.dao.StudentDao;
import com.etime.entity.Student;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;@WebServlet(name = "StudentServlet", value = "/StudentServlet")
public class StudentServlet extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//防止乱码request.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");String type = request.getParameter("type");//获取学生数据StudentDao studentDao = new StudentDao();if ("student".equals(type)) {List<Student> studentList = studentDao.selectStudent();request.setAttribute("list", studentList);request.getRequestDispatcher("showStudent.jsp").forward(request, response);//获取字符流,将数据显示出来/* PrintWriter writer = response.getWriter();writer.print("<h1>学生信息</h1>");for (Student student : studentList) {writer.println(student + "<br>");}writer.close();*/} else if ("selectName".equals(type)) {String selectText = request.getParameter("selectText");List<Student> list = studentDao.selectName(selectText);request.setAttribute("list", list);request.getRequestDispatcher("showStudent.jsp").forward(request, response);} else if ("insertStudent".equals(type)) {String name = request.getParameter("name");int age = Integer.parseInt(request.getParameter("age"));String sex = request.getParameter("sex");String email = request.getParameter("email");int i = studentDao.insert(name, age, sex, email);if (i != 0) {request.setAttribute("state", "添加成功!");request.getRequestDispatcher("index.jsp").forward(request, response);//response.sendRedirect("showStudent.jsp");} else {request.setAttribute("state", "添加失败!");request.getRequestDispatcher("index.jsp").forward(request, response);//response.sendRedirect("insertStudent.jsp");}} else if ("delete".equals(type)) {int id = Integer.parseInt(request.getParameter("id"));int i = studentDao.delete(id);if (i != 0) {request.setAttribute("state", "删除成功!");request.getRequestDispatcher("index.jsp").forward(request, response);} else {request.setAttribute("state", "删除失败");request.getRequestDispatcher("index.jsp").forward(request, response);}} else if ("newUpdate".equals(type)){String name = request.getParameter("name");//int age = Integer.parseInt(request.getParameter("age"));String age = request.getParameter("age");String sex = request.getParameter("sex");String email = request.getParameter("email");int id = Integer.parseInt(request.getParameter("id"));int i = studentDao.update(id, name, Integer.parseInt(age), sex, email);if (i != 0) {request.setAttribute("state", "修改成功!");request.getRequestDispatcher("index.jsp").forward(request, response);} else {request.setAttribute("state", "修改失败!");request.getRequestDispatcher("index.jsp").forward(request, response);}}}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}
}

部分。。。 

相关文章:

javaweb入门版学生信息管理系统-增删改查+JSP+Jstl+El

dao public class StudentDao {QueryRunner queryRunner QueryRunnerUtils.getQueryRunner();//查询全部学生信息public List<Student> selectStudent(){String sql "select * from tb_student";List<Student> students null;try {students queryRunn…...

云原生Kubernetes:K8S概述

目录 一、理论 1.云原生 2.K8S 3.k8s集群架构与组件 二、总结 一、理论 1.云原生 &#xff08;1&#xff09;概念 云原生是一种基于容器、微服务和自动化运维的软件开发和部署方法。它可以使应用程序更加高效、可靠和可扩展&#xff0c;适用于各种不同的云平台。 如果…...

nmap的使用

目录 nmap简介 主要作用 nmap原理 namp使用 options nmap列举远程机器开放端口 普通扫描 扫描范围端口 对几个端口探测 对所有端口进行探测 指定协议探测端口 扫描对应协议的所有端口 端口状态 nmap识别目标机器上服务的指纹 服务指纹 识别目标机器服务信息 …...

Python爬虫-某网酒店数据

前言 本文是该专栏的第5篇,后面会持续分享python爬虫案例干货,记得关注。 本文以某网的酒店数据为例,实现根据目标城市获取酒店数据。具体思路和方法跟着笔者直接往下看正文详细内容。(附带完整代码) 正文 地址:aHR0cHM6Ly93d3cuYnRoaG90ZWxzLmNvbS9saXN0L3NoYW5naGFp …...

了解atoi和offsetof

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 目录 文章目录 一、简介 二、深度剖析 1.atoi 2.offsetof 三、应用场景 一、简介二、深度剖析 1.atoi2.offsetof三、应用场景 一、简介 在C语言中&#xff0c;有许多…...

命令行编译VS工程

先输入以下命令&#xff0c;因为命令出错了&#xff0c;就会弹出帮助&#xff0c;如下&#xff1a; "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /help 反正就是Microsoft Visual Studio 的安装路径。 帮助界面如下&#xff1a…...

Linux防火墙命令

开启防火墙 systemctl start firewalld关闭防火墙 systemctl stop firewalld # 暂时关闭防火墙 systemctl disable firewalld # 永久关闭防火墙(禁用开机自启) systemctl enable firewalld # 永久开启防火墙(启用开机自启)重启防火墙 systemctl restart firewalld重载规则 …...

大数据平台数据脱敏是什么意思?有哪些方案?

大数据平台包含了海量多样化数据&#xff0c;所以保障大数据平台数据安全非常重要&#xff0c;数据脱敏就是手段之一。今天我们就来简单聊聊大数据平台数据脱敏是什么意思&#xff1f;有哪些方案&#xff1f; 大数据平台数据脱敏是什么意思&#xff1f; 大数据平台数据脱敏简…...

前后端分离不存在会话,sessionid不一致问题

目录 1.使用拦截器解决跨域的示例&#xff1a; 2.使用redis&#xff0c;不使用session 前后端不分离项目我们可以通过session存储数据&#xff0c;但是前后端分离时不存在会话&#xff0c;每次请求sessionid都会改变&#xff0c;当值我们储存的数据不能取出来。 1.使用拦截器…...

Python 3+ 安装及pip配置

Python 3 安装及pip安装升级 1. 安装Python依赖2. 在Linux服务器下载3. 创建python链接4. 配置pip 服务器环境&#xff1a;Linux CentOS 7 内核版本3.10 Python版本&#xff1a;3.10.6 由于CentOS 7默认安装python2.7&#xff0c;使用yum可以查到最新的python3版本为3.6.8&…...

StarRocks入门到熟练

1、部署 1.1、注意事项 需要根据业务需求设计严谨的集群架构&#xff0c;一般来说&#xff0c;需要注意以下几项&#xff1a; 1.1.1、FE数量及高可用 FE的Follower要求为奇数个&#xff0c;且并不建议部署太多&#xff0c;通常我们推荐部署1个或3个Follower。在三个Followe…...

Zabbix Api监控项值推送:zabbix_sender

用法示例&#xff1a; zabbix_sender [-v] -z server [-p port] [-I IP-address] [-t timeout] -s host -k key -o value其中&#xff1a; -z 即 --zabbix-server&#xff0c;Zabbix server的主机名或IP地址。如果主机由proxy监控&#xff0c;则应使用proxy的主机名或IP地址-…...

Shell脚本开发:printf和test命令的实际应用

目录 Shell printf 命令 打印简单文本 Shell test 命令 1、文件测试 2、字符串比较 3、整数比较 逻辑运算&#xff1a; Shell printf 命令 当你使用Shell中的printf命令时&#xff0c;它可以帮助你格式化和输出文本。 打印简单文本 这将简单地打印字符串"Hello, …...

React笔记(三)类组件(1)

一、组件的概念 使用组件方式进行编程&#xff0c;可以提高开发效率&#xff0c;提高组件的复用性、提高代码的可维护性和可扩展性 React定义组件的方式有两种 类组件&#xff1a;React16.8版本之前几乎React使用都是类组件 函数组件:React16.8之后&#xff0c;函数式组件使…...

Hugging Face实战-系列教程4:padding与attention_mask

&#x1f6a9;&#x1f6a9;&#x1f6a9;Hugging Face 实战系列 总目录 有任何问题欢迎在下面留言 本篇文章的代码运行界面均在notebook中进行 本篇文章配套的代码资源已经上传 上篇内容&#xff1a; Hugging Face实战-系列教程3&#xff1a;文本2分类 下篇内容&#xff1a; …...

睿趣科技:抖音开网店卖玩具怎么样

近年来&#xff0c;随着社交媒体平台的飞速发展&#xff0c;抖音作为一款短视频分享应用也迅速崭露头角。而在这个充满创业机遇的时代背景下&#xff0c;许多人开始探索在抖音平台上开设网店&#xff0c;尤其是卖玩具类商品&#xff0c;那么抖音开网店卖玩具究竟怎么样呢? 首先…...

简易虚拟培训系统-UI控件的应用4

目录 Slider组件的常用参数 示例-使用Slider控制主轴 示例-Slider控制溜板箱的移动 本文以操作面板为例&#xff0c;介绍使用Slider控件控制开关和速度。 Slider组件的常用参数 Slider组件下面包含了3个子节点&#xff0c;都是Image组件&#xff0c;负责Slider的背景、填充区…...

#include <graphics.h> #include <conio.h> #include<stdlib.h>无法打开源文件解决方案

一、问题描述 学习数据结构链表的过程中&#xff0c;在编写漫天星星闪烁的代码时&#xff0c;遇到了如下图所示的报错&#xff0c;#include <graphics.h> 、 #include <conio.h> 等无法打开源文件。 并且主程序中initgraph(初始化画布)、setfillcolor&#xff08;…...

【C语言】数据结构的基本概念与评价算法的指标

1. 数据结构的基本概念 1.1 基本概念和术语 1.1.1 数据 数据是信息的载体,是描述客观事物属性的数、字符及所有能输入到计算机中并被计算机程序识别和处理的符号的集合。数据是计算机程序加工的原料 1.1.2 数据元素 数据元素是数据的基本单位,通常作为一个整体进行考虑和…...

[PyTorch][chapter 54][Variational Auto-Encoder 实战]

前言&#xff1a; 这里主要实现&#xff1a; Variational Autoencoders (VAEs) 变分自动编码器 其训练效果如下 训练的过程中要注意调节forward 中的kle ,调参。 整个工程两个文件&#xff1a; vae.py main.py 目录&#xff1a; vae main 一 vae 文件名&#xff1a; vae…...

Ubuntu系统下交叉编译openssl

一、参考资料 OpenSSL&&libcurl库的交叉编译 - hesetone - 博客园 二、准备工作 1. 编译环境 宿主机&#xff1a;Ubuntu 20.04.6 LTSHost&#xff1a;ARM32位交叉编译器&#xff1a;arm-linux-gnueabihf-gcc-11.1.0 2. 设置交叉编译工具链 在交叉编译之前&#x…...

全球首个30米分辨率湿地数据集(2000—2022)

数据简介 今天我们分享的数据是全球30米分辨率湿地数据集&#xff0c;包含8种湿地亚类&#xff0c;该数据以0.5X0.5的瓦片存储&#xff0c;我们整理了所有属于中国的瓦片名称与其对应省份&#xff0c;方便大家研究使用。 该数据集作为全球首个30米分辨率、覆盖2000–2022年时间…...

屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!

5月28日&#xff0c;中天合创屋面分布式光伏发电项目顺利并网发电&#xff0c;该项目位于内蒙古自治区鄂尔多斯市乌审旗&#xff0c;项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站&#xff0c;总装机容量为9.96MWp。 项目投运后&#xff0c;每年可节约标煤3670…...

【决胜公务员考试】求职OMG——见面课测验1

2025最新版&#xff01;&#xff01;&#xff01;6.8截至答题&#xff0c;大家注意呀&#xff01; 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:&#xff08; B &#xff09; A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...

实现弹窗随键盘上移居中

实现弹窗随键盘上移的核心思路 在Android中&#xff0c;可以通过监听键盘的显示和隐藏事件&#xff0c;动态调整弹窗的位置。关键点在于获取键盘高度&#xff0c;并计算剩余屏幕空间以重新定位弹窗。 // 在Activity或Fragment中设置键盘监听 val rootView findViewById<V…...

Java面试专项一-准备篇

一、企业简历筛选规则 一般企业的简历筛选流程&#xff1a;首先由HR先筛选一部分简历后&#xff0c;在将简历给到对应的项目负责人后再进行下一步的操作。 HR如何筛选简历 例如&#xff1a;Boss直聘&#xff08;招聘方平台&#xff09; 直接按照条件进行筛选 例如&#xff1a…...

代理篇12|深入理解 Vite中的Proxy接口代理配置

在前端开发中,常常会遇到 跨域请求接口 的情况。为了解决这个问题,Vite 和 Webpack 都提供了 proxy 代理功能,用于将本地开发请求转发到后端服务器。 什么是代理(proxy)? 代理是在开发过程中,前端项目通过开发服务器,将指定的请求“转发”到真实的后端服务器,从而绕…...

云原生玩法三问:构建自定义开发环境

云原生玩法三问&#xff1a;构建自定义开发环境 引言 临时运维一个古董项目&#xff0c;无文档&#xff0c;无环境&#xff0c;无交接人&#xff0c;俗称三无。 运行设备的环境老&#xff0c;本地环境版本高&#xff0c;ssh不过去。正好最近对 腾讯出品的云原生 cnb 感兴趣&…...

HDFS分布式存储 zookeeper

hadoop介绍 狭义上hadoop是指apache的一款开源软件 用java语言实现开源框架&#xff0c;允许使用简单的变成模型跨计算机对大型集群进行分布式处理&#xff08;1.海量的数据存储 2.海量数据的计算&#xff09;Hadoop核心组件 hdfs&#xff08;分布式文件存储系统&#xff09;&a…...

Spring是如何解决Bean的循环依赖:三级缓存机制

1、什么是 Bean 的循环依赖 在 Spring框架中,Bean 的循环依赖是指多个 Bean 之间‌互相持有对方引用‌,形成闭环依赖关系的现象。 多个 Bean 的依赖关系构成环形链路,例如: 双向依赖:Bean A 依赖 Bean B,同时 Bean B 也依赖 Bean A(A↔B)。链条循环: Bean A → Bean…...