首页 > 编程语言 >2021级《JAVA语言程序设计》上机考试试题5

2021级《JAVA语言程序设计》上机考试试题5

时间:2022-12-24 21:22:21浏览次数:38  
标签:JAVA String 上机 resp req setAttribute Mima 2021 public

这是系统员功能实现,因为使用到了教师,所以教师的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,下面给页面

标签:JAVA,String,上机,resp,req,setAttribute,Mima,2021,public
From: https://www.cnblogs.com/JIANGzihao0222/p/17003405.html

相关文章