2021级《JAVA语言程序设计》上机考试试题5
这是系统员功能实现,因为使用到了教师,所以教师的Bean与Dao,以及更新的Servlet与service
Teacher
package Bean;
public class Teacher {
private String TeacherID;
private String Name;
private String College;
private String Professionals;
private String Role;
private String Mima;
public Teacher(String teacherID2, String name2, String college2, String professionals2, String role2, String mima2) {
// TODO Auto-generated constructor stub
Professionals = professionals2;
TeacherID = teacherID2;
Name = name2;
College = college2;
Role = role2;
Mima = mima2;
}
public String getMima() {
return Mima;
}
public void setMima(String mima) {
Mima = mima;
}
public String getTeacherID() {
return TeacherID;
}
public void setTeacherID(String teacherID) {
TeacherID = teacherID;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getCollege() {
return College;
}
public void setCollege(String college) {
College = college;
}
public String getProfessionals() {
return Professionals;
}
public void setProfessionals(String professionals) {
Professionals = professionals;
}
public String getRole() {
return Role;
}
public void setRole(String role) {
Role = role;
}
}
DaoTeacher
package dao;
import java.sql.Connection;
import java.sql.Statement;
import Bean.Teacher;
import util.Util;
public class DaoTeacher {
public static int AddTeacherr(Teacher tea) {
String sql = "insert into Teacher (TeacherID,Name,college,Professionals,Role,Mima) values('" + tea.getTeacherID() + "','" +tea.getName() + "','" +tea.getCollege() + "','" + tea.getProfessionals()+ "','" + tea.getRole()+"','" + tea.getMima() +"')";
System.out.println(sql);
Connection conn = Util.getConn();
Statement state = null;
int count=0;
try {
state = conn.createStatement();
count = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
Util.close(state, conn);
}
return count;
}
}只有一个,因为目前只涉及到一个
Servlet
package servlet;
import java.io.IOException;
import java.util.ArrayList;
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 javax.servlet.http.HttpSession;
import Bean.Student;
import Bean.Teacher;
import service.Service;
/**
* Servlet implementation class Servlet
*/
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Service service=new Service();
/**
* @see HttpServlet#HttpServlet()
*/
public Servlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String method = req.getParameter("method");
if ("Login".equals(method)) {
Login(req, resp);
}
if ("ViewinformationStudent".equals(method)) {
ViewinformationStudent(req, resp);
}
if ("updataStudent".equals(method)) {
updataStudent(req, resp);
}
if ("Register".equals(method)) {
Register(req, resp);
}
if ("Examineinformation".equals(method)) {
Examineinformation(req, resp);
}
if ("Allow".equals(method)) {
Allow(req, resp);
}
if ("ResetStudent".equals(method)) {
ResetStudent(req, resp);
}
if ("ViewinformationManager".equals(method)) {
ViewinformationManager(req, resp);
}
if ("AddTeacher".equals(method)) {
AddTeacher(req, resp);
}
}
private void AddTeacher(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String TeacherID = req.getParameter("TeacherID");
String Name= req.getParameter("Name");
String College = req.getParameter("College");
String Professionals = req.getParameter("Professionals");
String Role = req.getParameter("Role");
String Mima = req.getParameter("Mima");
Teacher tea=new Teacher(TeacherID,Name,College,Professionals,Role,Mima);
if(service.AddTeacher(tea)==1)
{
req.setAttribute("message", "添加成功");
req.getRequestDispatcher("Manager.jsp").forward(req,resp);
}else
{
req.setAttribute("message", "添加失败");
req.getRequestDispatcher("Addteacher.jsp").forward(req,resp);
}
}
private void ViewinformationManager(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
List<Student> bean = new ArrayList<Student>();
bean=service.ViewinformationManager();
req.setAttribute("bean", bean);
System.out.println(bean);
req.getRequestDispatcher("ViewinformationManager.jsp").forward(req,resp);
}
private void ResetStudent(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String StuID = req.getParameter("StuID");
if(service.ResetStudent(StuID)==1)
{ req.setAttribute("message", "成功");
req.getRequestDispatcher("Manager.jsp").forward(req,resp);
}
else
{
req.setAttribute("message", "失败");
req.getRequestDispatcher("ViewinformationManager.jsp").forward(req,resp);
}
}
private void Allow(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String StuID = req.getParameter("StuID");
if(service.Allow(StuID)==1)
{ req.setAttribute("message", "通过");
req.getRequestDispatcher("Manager.jsp").forward(req,resp);
}
else
{
req.setAttribute("message", "未通过");
req.getRequestDispatcher("Examineinformation.jsp").forward(req,resp);
}
}
private void Examineinformation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
List<Student> bean = new ArrayList<Student>();
bean=service.Examineinformation();
req.setAttribute("bean", bean);
System.out.println(bean);
req.getRequestDispatcher("Examineinformation.jsp").forward(req,resp);
}
private void Register(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String StuID = req.getParameter("StuID");
System.out.println(StuID);
String StuName = req.getParameter("StuName");
String sex = req.getParameter("sex");
String College = req.getParameter("College");
String Professionals = req.getParameter("Professionals");
String Phone = req.getParameter("Phone");
String Position = req.getParameter("Position");
String Mima = req.getParameter("Mima");
String Situation="未通过";
Student stu = new Student(StuID,StuName,sex,College,Professionals,Phone,Position,Mima,Situation);
if(service.Register(stu)==1)
{ req.setAttribute("message", "注册成功");
req.getRequestDispatcher("Student.jsp").forward(req,resp);
}
else
{
req.setAttribute("message", "注册失败,请重试");
req.getRequestDispatcher("Student.jsp").forward(req,resp);
}
}
private void updataStudent(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String mima1 = req.getParameter("mima1");
String mima2 = req.getParameter("mima2");
String mima3 = req.getParameter("mima3");
HttpSession session=req.getSession();
String StuID=(String)session.getAttribute("StuID");
String Mima=(String)session.getAttribute("Mima");
if(mima1.equals(Mima))
{
if(mima2.equals(mima3))
{
if(service.updataStudent(StuID,mima2)==1)
{
req.setAttribute("message", "修改成功");
session.setAttribute("Mima",mima2);
req.getRequestDispatcher("Student.jsp").forward(req,resp);
}
}
req.setAttribute("message", "新密码不相同");
req.getRequestDispatcher("updataStudent.jsp").forward(req,resp);
}
req.setAttribute("message", "原密码错误,请重试");
req.getRequestDispatcher("updataStudent.jsp").forward(req,resp);
}
private void ViewinformationStudent(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
HttpSession session=req.getSession();
String StuID=(String)session.getAttribute("StuID");
System.out.println(StuID);
String Mima=(String)session.getAttribute("Mima");
if(service.LoginStudent(StuID,Mima)==1)
{
Student stu=null;
//List<Beankecheng> bean = new ArrayList<Beankecheng>();
stu=service.ViewinformationStudent(StuID);
req.setAttribute("bean", stu);
req.getRequestDispatcher("ViewinformationStudent.jsp").forward(req,resp);
}
else
{
req.setAttribute("message", "查看失败,请重试");
req.getRequestDispatcher("Student.jsp").forward(req,resp);
}
}
private void Login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String zhiye = req.getParameter("zhiye");
String hao = req.getParameter("hao");
String Mima = req.getParameter("Mima");
HttpSession session=req.getSession();
if(zhiye.equals("学生"))
{ session.setAttribute("StuID",hao);
session.setAttribute("Mima",Mima);
String Situation=service.Judge(hao);
if((service.LoginStudent(hao,Mima)==1)&&(Situation.equals("通过")))
{
req.setAttribute("message", "登录成功");
req.getRequestDispatcher("Student.jsp").forward(req,resp);
}
else
{
req.setAttribute("message", "登录失败,请重新登录");
req.getRequestDispatcher("Screen.jsp").forward(req,resp);
}
}
if(zhiye.equals("专业教师"))
{
session.setAttribute("TeacherID",hao);
session.setAttribute("Mima",Mima);
}
if(zhiye.equals("专业负责人"))
{
session.setAttribute("TeacherID",hao);
session.setAttribute("Mima",Mima);
}
if(zhiye.equals("教学副院长"))
{session.setAttribute("TeacherID",hao);
session.setAttribute("Mima",Mima);
}
if(zhiye.equals("管理员"))
{
if((hao.equals("1"))&&Mima.equals("jiangzihao"))
{
req.setAttribute("message", "登录成功");
req.getRequestDispatcher("Manager.jsp").forward(req,resp);
}
else
{
req.setAttribute("message", "登录失败,请重新登录");
req.getRequestDispatcher("Screen.jsp").forward(req,resp);
}
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
Service
package service;
import java.util.List;
import Bean.Student;
import Bean.Teacher;
import dao.DaoStudent;
import dao.DaoTeacher;
public class Service {
public int LoginStudent(String stuID, String Mima) {
return DaoStudent.LoginStudent(stuID,Mima);
}
public Student ViewinformationStudent(String stuID) {
return DaoStudent.ViewinformationStudent(stuID);
}
public int updataStudent(String stuID, String mima) {
if(DaoStudent.updataStudent(stuID,mima)>0)
return 1;
return 0;
}
public int Register(Student stu) {
if(DaoStudent.Register(stu)>0)
return 1;
return 0;
}
public String Judge(String hao) {
return DaoStudent.Judge(hao);
}
public List<Student> Examineinformation() {
return DaoStudent.Examineinformation();
}
public int Allow(String stuID) {
if(DaoStudent.Allow(stuID)>0)
return 1;
return 0;
}
public int ResetStudent(String stuID) {
if(DaoStudent.ResetStudent(stuID)>0)
return 1;
return 0;
}
public List<Student> ViewinformationManager() {
return DaoStudent.ViewinformationManager();
}
public int AddTeacher(Teacher tea) {
if(DaoTeacher.AddTeacherr(tea)>0)
return 1;
return 0;
}
}
ok,下面给页面
2021级《JAVA语言程序设计》上机考试试题5的更多相关文章
- Java语言程序设计-助教篇
1. 给第一次上课(软件工程)的老师与助教 现代软件工程讲义 0 课程概述 给学生:看里面的第0个作业要求 2. 助教心得 美国视界(1):第一流的本科课堂该是什么样?(看里面的助教部分) 助教工作看 ...
- 全国计算机等级考试二级笔试样卷Java语言程序设计
一.选择题((1)-(35)每小题2分,共70分) 下列各题A).B).C).D)四个选项中,只有一个选项是正确的,请将正确选项涂写在答题卡相应位置上,答在试卷上不得分. (1)下列选项中不符合良好程 ...
- 《JAVA语言程序设计》上课笔记
教学目标:1.使学生了解JAVA课程的性质.定位.作用:为什么要学习JAVA?让学生知道如何学好JAVA: 教学内容: 一. 问几个问题 1. 你们到这里来干什么 ...
- Java语言程序设计复习提纲
这是我在准备Java考试时整理的提纲,如果是通过搜索引擎搜索到这篇博客的师弟师妹,建议还是先参照PPT和课本,这个大纲也不是很准确,自己总结会更有收获,多去理解含义,不要死记硬背,否则遇到概念辨析题 ...
- 0031 Java学习笔记-梁勇著《Java语言程序设计-基础篇 第十版》英语单词
第01章 计算机.程序和Java概述 CPU(Central Processing Unit) * 中央处理器 Control Unit * 控制单元 arithmetic/logic unit /ə ...
- Java语言程序设计(基础篇)第一章
第一章 计算机.程序和Java概述 1.1 引言 什么是程序设计呢? 程序设计就是创建(或者开发)软件,软件也称为程序. 1.2 什么是计算机 计算机是存储和处理数据的电子设备,计算机包括硬件(har ...
- JAVA语言程序设计课程评价
紧张的又短暂的一个学期结束了,这个学期也许将成为我人生中一个重要的转折点,作为一名半路出家的选手,在初次了解Java语言时我感到非常的迷茫与不知所措.因为之前很多同学都是通过假期时间在家自学,刚转入新 ...
- java语言程序设计(一)-1
java 语言的特点是: 强类型,制定了比较多的语言规范,尽可能在编译阶段检测出更多的错误及警告. 编译和解释,首先将源代码编译成codebyte,运行时,java的运行系统装载和链接需要执行的类,并 ...
- IT兄弟连 Java语法教程 Java语言入门 典面试题
1.请说明JVM.JRE和JDK是什么?它们有什么关系? JVM是Java虚拟机,Java Virtual Machine的缩写,是一个虚构出来的计算机,通过在实际的计算机上仿真模拟各种计算机功能来实 ...
- 《Java语言程序设计》上机实验
实验一 Java环境演练 [目的] ①安装并配置Java运行开发环境: ②掌握开发Java应用程序的3个步骤:编写源文件.编译源文件和运行应用程序: ③学习同时编译多个Java源文件. [内容 ...
随机推荐
- Opengl ES之YUV数据渲染
YUV回顾 记得在音视频基础知识介绍中,笔者专门介绍过YUV的相关知识,可以参考: <音视频基础知识-YUV图像> YUV数据量相比RGB较小,因此YUV适用于传输,但是YUV图不能直接用 ...
- 线上服务异常的定位、处理与优化的探索 - 第三章 Java虚拟机
Java虚拟机 之所以引入关于JVM的篇章,是发现多数项目发生的线上问题很大的几率源自JVM调优配置不当引起.对JVM的内存模型.GC垃圾回收机制.调优方式有一个系统化的了解后,可以快速处理或避免 ...
- JavaScript入门⑧-事件总结大全
JavaScript入门系列目录 JavaScript入门①-基础知识筑基 JavaScript入门②-函数(1)基础{浅出} JavaScript入门③-函数(2)原理{深入}执行上下文 JavaS ...
- Java开发如何通过IoT边缘ModuleSDK进行协议转换?
摘要:使用ModuleSDK开发插件应用,接入其他协议设备(如HTTP请求数据),将其他协议的数据转化为MQTT协议JSON数据上报到IoTDA. 本文分享自华为云社区<[华为云IoTEdge开 ...
- python基础语法&数据类型&运算符
1.标识符 # -*- coding:utf-8 -*- # @Time :2021/1/16 10:28 # @Author :QAbujiaban # @Email :wbxztoo@163.co ...
- CentOS7升级Linux内核
CentOS7升级Linux内核 什么是Linux内核 虽然时候使用 Linux 来表示整个操作系统,严格地说,Linux 只是个内核,而发行版的操作系统是一个完整功能的系统,它建立在内核之上,具有各 ...
- 疯狂吐槽 MAUI 以及 MAUI 入坑知识点
目录 窗口 窗口管理 如何限制一次只能打开一个程序 MAUI 程序安装模式 为 MAUI Blazor 设置语言 坑 ① 坑 ② 坑 ③ 配置 MAUI 项目使用管理员权限启动 问题背景 定制编译过程 ...
- day06-Spring管理Bean-IOC-04
Spring管理Bean-IOC-04 3.基于注解配置bean 3.1基本使用 3.1.1说明 基本说明:基于注解的方式配置bean,主要是项目开发中的组件,比如Controller,Service ...
- Hugging News #0106
每一周,我们的同事都会向社区的成员们发布一些关于 Hugging Face 相关的更新,包括我们的产品和平台更新.社区活动.学习资源和内容更新.开源库和模型更新等,我们将其称之为「Hugging Ne ...
- windows11 彻底修改c盘中文用户名
windows11 彻底修改c盘用户名 由于一开始注册的时候没有注意使用了中文名导致后来再使用一些应用的时候出现问题浪费了大量的时间找不出原因(例如:安装cuda 的时候在使用nvcc编译.cu文件的 ...