教师(MyBatis版)
查看个人信息(该功能主要是依靠session实现的,也算是远程传送数据吧)
根据教师id(唯一性)进行查询自己的基本信息,用类封装,然后再传递到jsp页面。输出即可
teacherLookInformation.java
package org.example.Servlet;
import org.example.Bean.teacher;
import org.example.Service.userService;
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 java.io.IOException;
@WebServlet("/teacherLookInformation")
public class teacherLookInformation extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
HttpSession session=req.getSession();
int id=(int)session.getAttribute("id");
teacher t=us.getIt(id);
req.setAttribute("t",t);
req.getRequestDispatcher("showTeacher.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
showTeacher.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>查看个人信息</title>
</head>
<body>
<center>
<form>
<table border="1">
<tr>
<td>教师工号</td> <td>${t.idT}</td>
</tr>
<tr>
<td>姓名</td> <td>${t.name}</td>
</tr>
<tr>
<td>职称</td> <td>${t.zhiCheng}</td>
</tr>
<tr>
<td>院系</td> <td>${t.yuan}</td>
</tr>
</table>
</form>
</center>
</body>
</html>
修改个人基本信息
先查询到自己的个人信息,然后传递到jsp页面,使用数据回显,将不允许修改的数据disabled一下,就改成了只读,其余改完之后,点击修改按钮就可以啦!
updatePersonal1.java
package org.example.Servlet;
import org.example.Bean.teacher;
import org.example.Bean.user;
import org.example.Service.userService;
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 java.io.IOException;
@WebServlet("/updatePersonal3")
public class updatePersonal3 extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
HttpSession session=req.getSession();
String password=(String)session.getAttribute("password");
int idT=us.getIDFromTeacher(password);
session.setAttribute("idT",idT);
teacher t=us.getIt(idT);
req.setAttribute("t",t);
req.getRequestDispatcher("updatePersonal2.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
updatePersonal2.jsp(修改个人信息界面)
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: 12140
Date: 2022/11/11
Time: 17:01
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>教师信息修改界面</title>
</head>
<body>
<center>
<form action="updateTeacher2" method="post">
<table border="1">
<input type="hidden" name="idT" value="${t.idT}">
<tr>
<td>姓名:</td>
<td><input type="text" name="name" value="${t.name}"></td>
</tr>
<tr>
<td>职称:</td>
<td><input type="radio" name="zhiCheng" value="助教" <c:if test="${t.zhiCheng eq '助教'}"> checked="checked"</c:if>>助教
<input type="radio" name="zhiCheng" value="讲师" <c:if test="${t.zhiCheng eq '讲师'}"> checked="checked"</c:if>>讲师
<input type="radio" name="zhiCheng" value="副教授" <c:if test="${t.zhiCheng eq '副教授'}"> checked="checked"</c:if>>副教授
<input type="radio" name="zhiCheng" value="教授" <c:if test="${t.zhiCheng eq '教授'}"> checked="checked"</c:if>>教授
</td>
</tr>
<tr>
<td>所属学院:</td>
<td>
<input type="radio" name="yuan" value="信息" <c:if test="${t.yuan eq '信息'}"> checked="checked"</c:if>>信息
<input type="radio" name="yuan" value="土木" <c:if test="${t.yuan eq '土木'}"> checked="checked"</c:if>>土木
<input type="radio" name="yuan" value="机械" <c:if test="${t.yuan eq '机械'}"> checked="checked"</c:if>>机械
<input type="radio" name="yuan" value="电气" <c:if test="${t.yuan eq '电气'}"> checked="checked"</c:if>>电气
<input type="radio" name="yuan" value="交通" <c:if test="${t.yuan eq '交通'}"> checked="checked"</c:if>>交通
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="修改"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
updateTeacher2.java(修改操作实现界面)
package org.example.Servlet;
import org.example.Bean.teacher;
import org.example.Service.userService;
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 java.io.IOException;
@WebServlet("/updateTeacher2")
public class updateTeacher2 extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
HttpSession session=req.getSession();
int idT=(int)session.getAttribute("idT");
String name=req.getParameter("name");
String zhiCheng=req.getParameter("zhiCheng");
String yuan=req.getParameter("yuan");
teacher t=new teacher();
t.setIdT(idT);
t.setName(name);
t.setZhiCheng(zhiCheng);
t.setYuan(yuan);
us.updateTeacher(t);
req.getRequestDispatcher("index.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
修改个人密码
很怯的密码修改,建议使用下面那种方式哦!(这个使用的是数据回显)
password4.java(修改密码)
package org.example.Servlet;
import org.example.Bean.teacherAdmin;
import org.example.Bean.userAdmin;
import org.example.Service.userService;
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 java.io.IOException;
@WebServlet("/password4")
public class password4 extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
HttpSession session=req.getSession();
int id=(int)session.getAttribute("id");
teacherAdmin u=us.getIt1(id);
req.setAttribute("u",u);
req.getRequestDispatcher("password5.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
password5.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改密码界面</title>
</head>
<body>
<center>
<form action="password6" method="post">
<table border="1">
<input type="hidden" name="id" value="${u.id}">
<tr>
<td>请输入你想要的新密码:</td>
<td><input type="text" name="password" value="${u.password}"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="修改"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
password6.java
package org.example.Servlet;
import org.example.Bean.userAdmin;
import org.example.Service.userService;
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 java.io.IOException;
@WebServlet("/password6")
public class password6 extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String password=req.getParameter("password");
userAdmin u=new userAdmin();
u.setPassword(password);
us.updatePasswordP(u);
req.setAttribute("u",u);
req.getRequestDispatcher("index.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
这个里面的修改密码界面是利用数据回显实现的,之前的房产管理系统里面的修改密码的操作是用旧密码和新密码来实现的,下面的方式就是那种方式:
修改密码:
updateAgentPassword.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>房产经纪修改密码界面</title>
</head>
<body>
<center>
<form action="updateAgentPassword" method="post">
<table border="1">
<tr>
<td>旧密码:</td>
<td><input type="text" name="oldPass" id="oldPass"></td>
</tr>
<tr>
<td>新密码:</td>
<td><input type="password" name="newPassOne" id="newPassOne"></td>
</tr>
<tr>
<td>请再次确认新密码:</td>
<td><input type="password" name="newPassTwo" id="newPassTwo" onkeyup="checkPass()"><span id="clue"></span></td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="submit" value="修改"></td>
</tr>
</table>
</form>
<%--判断两次输入的新密码是否一致--%>
<script>
function checkPass(){
var newPassOne=document.getElementById("newPassOne").value;
var newPassTwo=document.getElementById("newPassTwo").value;
if(newPassOne==""||newPassTwo==""){
document.getElementById("clue").innerHTML="<font color=red>密码不能空</font>"
document.getElementById("submit").disabled=true;
}else{
if(newPassOne==newPassTwo){
document.getElementById("clue").innerHTML="<font color=green>密码一致</font>"
document.getElementById("submit").disabled=false;
}else{
document.getElementById("clue").innerHTML="<font color=red>密码不一致</font>"
document.getElementById("submit").disabled=true;
}
}
}
</script>
</center>
</body>
</html>
updateAgentPassword.java
package org.example.Servlet;
import org.example.Bean.agentAdmin;
import org.example.Bean.userAdmin;
import org.example.Service.HouseService;
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 java.io.IOException;
@WebServlet("/updateAgentPassword")
public class updateAgentPassword extends HttpServlet {
private HouseService hs=new HouseService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String oldPass=req.getParameter("oldPass");
int m=hs.selectUserPassword(oldPass);
if(m==1) {
String newPassOne = req.getParameter("newPassOne");
HttpSession session = req.getSession();
String agentID = (String) session.getAttribute("agentID");
agentAdmin aa = new agentAdmin();
aa.setAgentID(agentID);
aa.setAgentPassword(newPassOne);
hs.updateThePasswordAgent(aa);
req.getRequestDispatcher("index.jsp").forward(req, resp);
}else{
req.getRequestDispatcher("failed.jsp").forward(req,resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
修改个人所授课的限制人数
将本人所授课遍历出来,点击每一条数据后面的修改,就可以跳到那条数据的修改界面,点击修改即可
teacherUpdatePerson.java
package org.example.Servlet;
import org.example.Bean.ke;
import org.example.Service.userService;
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 java.io.IOException;
import java.util.List;
@WebServlet("/teacherUpdatePerson")
public class teacherUpdatePerson extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
HttpSession session=req.getSession();
int id=(int)session.getAttribute("id");
List<ke> list=us.getBasic2(id);
req.setAttribute("list",list);
req.getRequestDispatcher("teacherUpdatePerson2.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
teacherUpdatePerson2.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: 12140
Date: 2022/11/12
Time: 11:08
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>选课信息界面</title>
</head>
<body>
<center>
<form>
<table border="1">
<tr>
<td>课程名称</td>
<td>开课时间</td>
<td>开课节次</td>
<td>选课限制人数</td>
<td>操作</td>
</tr>
<c:forEach items="${list}" var="ke">
<tr>
<td>${ke.className}</td>
<td>${ke.startTime}</td>
<td>${ke.startNum}</td>
<td>${ke.kPerson}</td>
<td><a href="teacherUpdatePerson3?idK=${ke.idK}">修改</a></td>
</tr>
</c:forEach>
</table>
</form>
</center>
</body>
</html>
teacherUpdatePerson3.java
package org.example.Servlet;
import org.example.Bean.ke;
import org.example.Service.userService;
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 java.io.IOException;
@WebServlet("/teacherUpdatePerson3")
public class teacherUpdatePerson3 extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String idK1=req.getParameter("idK");
int idK=Integer.parseInt(idK1);
HttpSession session =req.getSession();
session.setAttribute("idK",idK);
ke k=us.getOne(idK);
req.setAttribute("k",k);
req.getRequestDispatcher("teacherUpdatePerson4.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
teacherUpdatePerson4.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改界面</title>
</head>
<body>
<center>
<form action="teacherUpdateClass5" method="post">
<table border="1">
<tr>
<td>课程名称:</td>
<td><input type="text" name="className" value="${k.className}" disabled></td>
</tr>
<tr>
<td>开课节次:</td>
<td><input type="text" name="startNum" value="${k.startNum}" disabled></td>
</tr>
<tr>
<td>开课时间:</td>
<td><input type="text" name="startTime" value="${k.startTime}" disabled></td>
</tr>
<tr>
<td>选课限制人数:</td>
<td><input type="text" name="kPerson" value="${k.kPerson}"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="修改"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
teacherUpdatePerson5.java
package org.example.Servlet;
import org.example.Bean.ke;
import org.example.Service.userService;
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 javax.swing.*;
import java.io.IOException;
@WebServlet("/teacherUpdateClass5")
public class teacherUpdateClass5 extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
HttpSession session=req.getSession();
int idK=(int)session.getAttribute("idK");
String kPerson1=req.getParameter("kPerson");
int kPerson=Integer.parseInt(kPerson1);
ke k=new ke();
k.setIdK(idK);
k.setkPerson(kPerson);
us.updatePersonNum1(k);
req.setAttribute("k",k);
req.getRequestDispatcher("index.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
查询个人课表
根据自己的教师id查询list集合的数据,直接在下一个jsp页面显示出来即可
teacherCheckPersonalClass.java
package org.example.Servlet;
import org.example.Bean.ke;
import org.example.Service.userService;
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 java.io.IOException;
import java.util.List;
@WebServlet("/teacherCheckPersonalClass")
public class teacherCheckPersonalClass extends HttpServlet {
private userService us=new userService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
HttpSession session=req.getSession();
int id=(int)session.getAttribute("id");
List<ke> list=us.getBasic2(id);
req.setAttribute("list",list);
req.getRequestDispatcher("teacherCheckPersonalClass.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req,resp);
}
}
teacherCheckPersonalClass.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: 12140
Date: 2022/11/12
Time: 11:00
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>查看个人课表</title>
</head>
<body>
<center>
<form>
<table border="1">
<tr>
<td>课程名称</td>
<td>开课时间</td>
<td>开课节次</td>
<td>选课限制人数</td>
</tr>
<c:forEach items="${list}" var="ke">
<tr>
<td>${ke.className}</td>
<td>${ke.startTime}</td>
<td>${ke.startNum}</td>
<td>${ke.kPerson}</td>
</tr>
</c:forEach>
</table>
</form>
</center>
</body>
</html>
标签:教师,http,选课,resp,req,学生,import,servlet,javax
From: https://www.cnblogs.com/liuzijin/p/16884798.html