选课系统中用到了4个表,分别是classs、yonghu、teacher、student。在用户中存放管理员的信息name和password以及id,在另三个表中存放对应的数据如图:

calss:

teacher:

student:

yonghu:

首先root用户提前定义好名字以及密码,老师和学生可以由root进行增加

登录时根据选择的用户类型将输入的用户名和密码与数据库中对应的进行判断,根据用户的不同类型跳转到不同的界面。登陆成功后将登录用户的名字存放到session中,之后进行一系列例如更改个人信息、添加课程时直接调用session中的当前用户的名字进行更改。

下面是代码:

DAO:

 package Dao;

 import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.sql.ResultSet;
import DBUtil.DBUtil;
import Entity.teacher;
import Entity.student;
import Entity.Classs;
public class Dao {
public String dopost(String username,String password,String leibie) {
String i="-1";
String sql=null;
if(leibie.equals("老师"))
{
sql="select * from teacher where xingming = '"+username+"'";
}
else if(leibie.equals("学生"))
{
sql="select * from student where xingming = '"+username+"'";
}
else if(leibie.equals("管理员"))
{
sql="select * from yonghu where name = '"+username+"'";
}
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while(rs.next()) {
String password1 = rs.getString("password");
if(password.equals(password1)) {
i=rs.getString("id");
}
break;
}
}catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(rs,state, conn);
}
return i;
}
public boolean teadd(teacher tea) { String sql = "insert into teacher(gonghao,xingbie,xingming,xuexiao,zhicheng,password,id) values('"+ tea.getGonghao() + "','"+ tea.getXingbie() +"','"+ tea.getXingming() +"','" + tea.getXuexiao() +"','"+ tea.getZhicheng() +"' , '"+tea.getPassword()+"' , '"+tea.getId()+"')";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0; try {
state = conn.createStatement();
a=state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally { DBUtil.close(state, conn);
} if (a > 0) {
f = true;
}
return f; }
public boolean stadd(student stu) { String sql = "insert into student(xuehao,xingming,xingbie,banji,zhuanye,password,id) values('"+ stu.getXuehao() + "','"+ stu.getXingming() +"','"+ stu.getXingbie() +"','" + stu.getBanji() +"','"+ stu.getZhuanye() +"' , '"+stu.getPassword()+"' , '"+stu.getId()+"')";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0; try {
state = conn.createStatement();
a=state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally { DBUtil.close(state, conn);
} if (a > 0) {
f = true;
}
return f; }
public boolean claadd(String bianhao,String name,String number,String prename) { String sql = "insert into classs(clahao,claname,number,tea,num) values('"+ bianhao + "','"+ name +"','"+ number +"','"+prename+"', '0')";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0; try {
state = conn.createStatement();
a=state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally { DBUtil.close(state, conn);
} if (a > 0) {
f = true;
}
return f; }
public boolean teagai(String leibie,String neirong,String prename) { String sql = "update teacher set "+ leibie+" = '"+ neirong+"' "+"where xingming = '"+prename+"'";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0; try {
state = conn.createStatement();
a=state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally { DBUtil.close(state, conn);
} if (a > 0) {
f = true;
}
return f; }
public boolean stugai(String leibie,String neirong,String prename) { String sql = "update student set "+ leibie+" = '"+ neirong+"' "+"where xingming = '"+prename+"'";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0; try {
state = conn.createStatement();
a=state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally { DBUtil.close(state, conn);
} if (a > 0) {
f = true;
}
return f; }
public List<Classs> list(){
String sql="select * from classs";
Connection conn = DBUtil.getConn();
Statement state =null;
ResultSet rs = null;
List<Classs> list = new ArrayList<>();
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
Classs bean = null;
while (rs.next()) {
String claname1=rs.getString("claname");
String clahao1=rs.getString("clahao");
String number1=rs.getString("number");
String tea1=rs.getString("tea");
String num1=rs.getString("num");
bean = new Classs(clahao1,claname1,number1,tea1,num1);
list.add(bean); } }catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(rs,state, conn);
}
return list;
}
public boolean jia(String num,String number,String clahao) {
boolean f=false;
int n1=Integer.parseInt(num);
int n2=Integer.parseInt(number);
if(n1<n2) {
n1++;
String num1=null;
num1 = String.valueOf(n1);
String sql = "update classs set num = '"+num1+"' where clahao = '"+clahao+"'";
Connection conn = DBUtil.getConn();
Statement state = null;
int a = 0;
try {
state = conn.createStatement();
a=state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally { DBUtil.close(state, conn);
} if (a > 0) {
f = true;
} }
return f;
}
}

DBUtil:

 package DBUtil;

 import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; public class DBUtil { public static String db_url = "**********";
public static String db_user = "****";
public static String db_pass = "******"; public static Connection getConn () {
Connection conn = null; try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(db_url, db_user, db_pass);
} catch (Exception e) {
e.printStackTrace();
} return conn;
}//end getConn public static void close (Statement state, Connection conn) {
if (state != null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
} if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static void close (ResultSet rs, Statement state, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
} if (state != null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
} if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static void main(String[] args) throws SQLException {
Connection conn = getConn();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql ="select * from yonghu";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next()){
System.out.println("连接成功");
}else{
System.out.println("连接失败");
}
}
}

Entity中定义了4个类:

classs:

 package Entity;

 public class Classs {
private String clahao;
private String claname;
private String number;
private String tea;
private String num;
public String getClahao() {
return clahao;
}
public void setClahao(String clahao) {
this.clahao = clahao;
}
public String getClaname() {
return claname;
}
public void setClaname(String claname) {
this.claname = claname;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getTea() {
return tea;
}
public void setTea(String tea) {
this.tea = tea;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public Classs(String clahao,String claname,String number, String tea,String num) {
super();
this.clahao=clahao;
this.claname=claname;
this.number=number;
this.tea=tea;
this.num=num;
} }

另外三个是user、teacher、student结构和这个一样就不上了。

Servlet:

 package Servlet;
import java.io.IOException;
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 Entity.teacher;
import Entity.User;
import Entity.student;
import Entity.Classs;
import Dao.Dao; @WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L; public Servlet() {
super(); }
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String method = req.getParameter("method");
if ("dopost".equals(method)) {
dopost(req,resp);
}
if ("tiao".equals(method)) {
tiao(req,resp);
}
if ("teadd".equals(method)) {
teadd(req,resp);
}
if ("stadd".equals(method)) {
stadd(req,resp);
}
if ("claadd".equals(method)) {
claadd(req,resp);
}
if ("teagai".equals(method)) {
teagai(req,resp);
}
if ("stugai".equals(method)) {
stugai(req,resp);
}
if("list".equals(method)){
list(req,resp);
}
if("jia".equals(method)) {
jia(req,resp);
} } private void dopost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8");
String username = req.getParameter("username");
String password = req.getParameter("password");
String leibie=req.getParameter("leibie");
HttpSession session = req.getSession();
session.setAttribute("prename",username);
Dao dao=new Dao();
String id=dao.dopost(username, password,leibie);
if(id.equals("-1")) {
req.setAttribute("message", "登录失败!");
req.getRequestDispatcher("index.jsp").forward(req,resp);
}
else if(id.equals("0")) {
req.setAttribute("message", "登陆成功!");
req.getRequestDispatcher("allteacher.jsp").forward(req,resp);
}
else if(id.equals("1")) {
req.setAttribute("message", "登陆成功!");
req.getRequestDispatcher("allstudent.jsp").forward(req,resp);
}
else if(id.equals("2")) {
req.setAttribute("message", "登陆成功!");
req.getRequestDispatcher("root.jsp").forward(req,resp);
}
}
private void tiao(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String leibie=req.getParameter("leibie");
if(leibie.equals("学生")) {
req.setAttribute("message", "请开始添加学生信息!");
req.getRequestDispatcher("student.jsp").forward(req,resp);
}
if(leibie.equals("老师")) {
req.setAttribute("message", "请添加老师信息!");
req.getRequestDispatcher("teacher.jsp").forward(req,resp);
}
}
private void teadd(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String gonghao=req.getParameter("gonghao");
String xingming=req.getParameter("xingming");
String xingbie=req.getParameter("xingbei");
String xuexiao=req.getParameter("xuexiao");
String zhicheng=req.getParameter("zhicheng");
String password=req.getParameter("password");
String id="0";
teacher tea=new teacher(gonghao,xingbie,xingming,xuexiao,zhicheng,password,id);
Dao dao =new Dao();
boolean f=dao.teadd(tea);
if(f) {
req.setAttribute("message", "添加成功!");
req.getRequestDispatcher("root.jsp").forward(req,resp);
} else {
req.setAttribute("message", "添加失败!");
req.getRequestDispatcher("teacher.jsp").forward(req,resp);
}
}
private void stadd(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String xuehao=req.getParameter("xuehao");
String xingming=req.getParameter("xingming");
String xingbie=req.getParameter("xingbei");
String banji=req.getParameter("banji");
String zhuanye=req.getParameter("zhuanye");
String password=req.getParameter("password");
String id="1";
student stu=new student(xuehao,xingming,xingbie,banji,zhuanye,password,id);
Dao dao =new Dao();
boolean f=dao.stadd(stu);
if(f) {
req.setAttribute("message", "添加成功!");
req.getRequestDispatcher("root.jsp").forward(req,resp);
} else {
req.setAttribute("message", "添加失败!");
req.getRequestDispatcher("teacher.jsp").forward(req,resp);
}
}
private void claadd(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
HttpSession session = req.getSession();
String prename=null;
prename=(String)session.getAttribute("prename");
String bianhao=req.getParameter("hao");
String name=req.getParameter("name");
String number=req.getParameter("number");
Dao dao =new Dao();
boolean f=dao.claadd(bianhao,name,number,prename);
if(f) {
req.setAttribute("message", "添加成功!");
req.getRequestDispatcher("allteacher.jsp").forward(req,resp);
} else {
req.setAttribute("message", "添加失败!");
req.getRequestDispatcher("addclass.jsp").forward(req,resp);
}
}
private void teagai(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
HttpSession session = req.getSession();
String prename=null;
prename=(String)session.getAttribute("prename");
String leibie=req.getParameter("leibie");
String neirong=req.getParameter("neirong"); Dao dao =new Dao();
boolean f=dao.teagai(leibie,neirong,prename);
if(f) {
req.setAttribute("message", "修改成功!");
req.getRequestDispatcher("allteacher.jsp").forward(req,resp);
} else {
req.setAttribute("message", "修改失败!");
req.getRequestDispatcher("updatetea.jsp").forward(req,resp);
}
}
private void stugai(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
HttpSession session = req.getSession();
String prename=null;
prename=(String)session.getAttribute("prename");
String leibie=req.getParameter("leibie");
String neirong=req.getParameter("neirong");
Dao dao =new Dao();
boolean f=dao.stugai(leibie,neirong,prename);
if(f) {
req.setAttribute("message", "修改成功!");
req.getRequestDispatcher("allstudent.jsp").forward(req,resp);
} else {
req.setAttribute("message", "修改失败!");
req.getRequestDispatcher("updatestu.jsp").forward(req,resp);
}
}
private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ Dao dao=new Dao();
List<Classs> holds = dao.list();
req.setAttribute("holds", holds);
req.getRequestDispatcher("xuan.jsp").forward(req,resp);
}
private void jia(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("UTF-8");
String num=req.getParameter("num");
String number=req.getParameter("number");
String clahao=req.getParameter("clahao");
Dao dao=new Dao();
boolean f=dao.jia(num, number, clahao);
if(f) {
req.setAttribute("message", "选课成功!");
req.getRequestDispatcher("allstudent.jsp").forward(req,resp);
} else {
req.setAttribute("message", "选课失败!");
req.getRequestDispatcher("xuan.jsp").forward(req,resp);
}
}
}

然后就是各个jsp界面了

index:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if (message != null && !"".equals(message)) {
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
var asd=request.getAttribute("username");
</script>
<%
}
%>
<form action="Servlet?method=dopost" method="post">
<div>
用户名<input type="text" name="username" />
</div>
<div>
密码<input type="password" name="password" />
</div>
<div>
<th>类别</th> <select name="leibie">
<option>学生</option>
<option>老师</option>
<option>管理员</option>
</select>
</div>
<div>
<input type="submit" value="登录" />
</div>
</form>
</body>
</html>

root:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>当前位置:添加信息</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if (message != null && !"".equals(message)) {
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
var asd=request.getAttribute("username");
</script>
<%
}
%>
<form action="Servlet?method=tiao" method="post">
<div>
<th>类别</th> <select name="leibie">
<option>学生</option>
<option>老师</option>
</select>
</div>
<div>
<input type="submit" value="提交" />
</div> </form> </body> </html>

teacher:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加老师信息</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if (message != null && !"".equals(message)) {
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
var asd=request.getAttribute("name");
</script>
<%
}
%>
<form action="Servlet?method=teadd" method="post" >
<table > <tr>
<th>工号:</th>
<td>
<input name="gonghao" type="text" />
</td>
</tr>
<tr>
<th>姓名:</th>
<td>
<input name="xingming" type="text" />
</td>
</tr>
<tr>
<th>性别:</th>
<td>
<input name="xingbei" type="radio" value="男" />男
<input name="xingbei" type="radio" value="女" />女
</td>
</tr>
<tr>
<th>学校:</th>
<td>
<input name="xuexiao" type="text">
</td>
</tr>
<tr>
<th>职称:</th>
<td>
<input name="zhicheng" type="text">
</td>
</tr>
<tr>
<th>密码:</th>
<td>
<input name="password" type="text">
</td> </tr>
<tr>
<td >
<input type="submit" value="提交" />
</td>
</tr> </table> </form>
</body>
</html>

student:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加学生信息</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if (message != null && !"".equals(message)) {
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
var asd=request.getAttribute("name");
</script>
<%
}
%>
<form action="Servlet?method=stadd" method="post">
<table> <tr>
<th>学号:</th>
<td><input name="xuehao" type="text" /></td>
</tr>
<tr>
<th>姓名:</th>
<td><input name="xingming" type="text" /></td>
</tr>
<tr>
<th>性别:</th>
<td><input name="xingbei" type="radio" value="男" />男 <input
name="xingbei" type="radio" value="女" />女</td>
</tr>
<tr>
<th>班级:</th>
<td><input name="banji" type="text"></td>
</tr>
<tr>
<th>专业:</th>
<td><input name="zhuanye" type="text"></td>
</tr>
<tr>
<th>密码:</th>
<td><input name="password" type="text"></td>
</tr>
<tr>
<td><input type="submit" value="提交" /></td>
</tr> </table> </form>
</body>
</html>

allteacher:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>当前位置:主页</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if (message != null && !"".equals(message)) {
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
var asd=request.getAttribute("username");
</script>
<%
}
%>
<% String prename=null;
prename=request.getParameter(prename);
%> <div align="center">
<div>当前用户:${prename }</div>
<div> <a href="updatetea.jsp">修改个人信息</a>
</div> <div>
<a href="addclass.jsp">添加课程信息</a> </div> </div> </body> </html>

allstudent:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>当前位置:主页</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if (message != null && !"".equals(message)) {
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
var asd=request.getAttribute("username");
</script>
<%
}
%>
<% String prename=null;
prename=request.getParameter(prename);
%> <div align="center">
<div>当前用户:${prename }</div>
<div> <a href="updatestu.jsp">修改个人信息</a>
</div> <div>
<a href="Servlet?method=list">选课</a> </div> </div> </body> </html>

addclass:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加老师信息</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if (message != null && !"".equals(message)) {
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
var asd=request.getAttribute("name");
</script>
<%
}
%>
<form action="Servlet?method=claadd" method="post">
<table> <tr>
<th>课程编号:</th>
<td><input name="hao" type="text" /></td>
</tr>
<tr>
<th>课程名称:</th>
<td><input name="name" type="text" /></td>
</tr>
<tr>
<th>选课人数:</th>
<td><input name="number" type="text" /></td>
</tr>
<tr>
<td><input type="submit" value="提交" /></td>
</tr> </table> </form>
</body>
</html>

updatestu:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<%
String prename=null;
prename=request.getParameter(prename);
%> <div align="center">
<div>${prename }</div>
<form action="Servlet?method=stugai" method="post" > <div>
<th>类别</th>
<select name="leibie">
<option>xuehao</option>
<option>xingming</option>
<option>xingbie</option>
<option>banji</option>
<option>zhuanye</option>
</select>
</div>
<div>
<input type="text" name="neirong" />
</div> <div>
<input type="submit" value="提交" />
</div>
</form>
</div>
</body>
</html>

updatetea:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<%
String prename=null;
prename=request.getParameter(prename);
%>
<div align="center">
<div>当前用户:${prename }</div>
<form action="Servlet?method=teagai" method="post"> <div>
<th>类别</th> <select name="leibie">
<option>gonghao</option>
<option>xingming</option>
<option>xingbie</option>
<option>xuexiao</option>
<option>zhicheng</option>
</select>
</div>
<div>
<input type="text" name="neirong" />
</div> <div>
<input type="submit" value="提交" />
</div>
</form>
</div>
</body>
</html>

xuan:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>课程信息</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if (message != null && !"".equals(message)) {
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
var asd=request.getAttribute("username");
</script>
<%
}
%>
<table >
<tr>
<td>课程编号</td>
<td>课程名称</td>
<td>任课老师</td>
<td>已选人数</td>
<td>课程人数</td>
</tr>
<!-- forEach遍历出adminBeans -->
<c:forEach items="${holds}" var="item" varStatus="status">
<tr>
<td>${item.clahao}</td>
<td>${item.claname}</td>
<td>${item.tea}</td>
<td>${item.num}</td>
<td>${item.number}</td>
<td><a href="Servlet?method=jia&num=${item.num }&number=${item.number}&clahao=${item.clahao}" >选课</a> </td>
</tr>
</c:forEach>
</table> </body>
</html>

这就是全部的代码了,做这个系统的过程中我遇到的难点是如何保持一个用户的登录状态,可以再之后这个用户进行操作时简单便捷的获取当前用户的信息,找了资料之后发现session对象符合我的要求,便开始在我原来的代码上进行更改。最终实现了登录状态的保持。

javaweb-选课系统的更多相关文章

  1. 简单的JAVAWeb选课系统

    该系统管理员可以添加和删除学生.教师,教师可以修改自己信息.添加课程.浏览自己课程,学生可以修改自己的信息.选课.浏览全部课程. 首先展示文件: 然后就是一次展示代码: Guanli包中代码: pac ...

  2. Javaweb实现简单的选课系统(主要技术包括jsp、Servlet、Javabean)

    一.背景信息: 首先,这个选课系统是上周一老师在课堂上让我们做的测试,考试时长三个小时,我只做了一半,也没有实现选课流程. 由于上周忙于写实验报告没有时间继续完成这个测试.这周用前天和昨天一共七个小时 ...

  3. java web知识点复习,重新编写学生选课系统的先关操作。

    为了复习之前学习的相关的html,javaweb等知识.自己有重新编写了一遍学生选课系统. 下面主要展示登录界面的代码,以及各个大的主页面的相关jsp. <%@ page language=&q ...

  4. 从零开始学Python06作业思路:学生选课系统

    一,作业要求 选课系统: 管理员: 创建老师:姓名.性别.年龄.资产 创建课程:课程名称.上课时间.课时费.关联老师 学生:用户名.密码.性别.年龄.选课列表[].上课记录{课程1:[di,a,]} ...

  5. python之选课系统详解[功能未完善]

    作业需求 思路:1.先写出大体的类,比如学校类,学生类,课程类--   2.写出类里面大概的方法,比如学校类里面有创建讲师.创建班级-- 3.根据下面写出大致的代码,并实现其功能       遇到的困 ...

  6. Python开发程序:选课系统-改良版

    程序名称: 选课系统 角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. ...

  7. python实现学生选课系统 面向对象的应用:

    一.要求: 选课系统 管理员: 创建老师:姓名.性别.年龄.资产 创建课程:课程名称.上课时间.课时费.关联老师 使用pickle保存在文件 学生: 学生:用户名.密码.性别.年龄.选课列表[].上课 ...

  8. Python开发程序:选课系统

    本节作业: 选课系统 角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. ...

  9. python 面向对象 class 老男孩选课系统

    要求:1. 创建北京.上海 2 所学校 class2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. 课程包含,周期,价格,通过学校创建课 ...

  10. 一个简单的python选课系统

    下面介绍一下自己写的python程序,主要是的知识点为sys.os.json.pickle的模块应用,python程序包的的使用,以及关于类的使用. 下面是我的程序目录: bin是存放一些执行文件co ...

随机推荐

  1. Python操作pymysql写入数据库时的错误

    错误一 InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE6\\xAD\\xA3 ...

  2. 数组的查找,删除 Day07

    package com.sxt.arraytest2; /* * 形参列表的作用:1.接受方法调用处传来的实参 * 2.规定了实参传入数据的类型 */ import java.util.Arrays; ...

  3. Java练习 SDUT-1171_保留整数

    C语言实验--保留整数 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入一个字符串str1,把其中的连续非数字的字符 ...

  4. laravel 5.6接入微信第三方授权登陆的主要步骤

    https://yq.aliyun.com/articles/590435 摘要: 这方面,php已很成熟了, 综合下面这个链接,基本上调试一下就可以搞定了. 这方面,php已很成熟了, 综合下面这个 ...

  5. laravel 定时任务通过队列发送邮件

    https://www.jianshu.com/p/f6b94596098e 关于laravel发送邮件,请先参考我的另一片文章:laravel sendcloud发送邮件,再继续往下看. 1.用da ...

  6. 学习HTML<audio>标签

    首先来看下这个例子: <audio controls autoplay="autoplay"> <source src="horse.ogg" ...

  7. 【tensorflow】】模型优化(一)指数衰减学习率

    指数衰减学习率是先使用较大的学习率来快速得到一个较优的解,然后随着迭代的继续,逐步减小学习率,使得模型在训练后期更加稳定.在训练神经网络时,需要设置学习率(learning rate)控制参数的更新速 ...

  8. Python--day70--csrf简单用法、 跨站请求伪造和csrf_token使用

    1,csrf简单用法 2,Django里面的setting加入了防跨站伪造:这段代码帮你生成特殊字符串,帮你塞到html页面中来 3,csrf_token使用:

  9. 【知识小结】Git 个人学习笔记及心得

    https://mp.weixin.qq.com/s/D96dXYfu3XAA4ac456qo0g git架构 工作区:就是你在电脑里能看到的目录. 版本库:工作区有一个隐藏目录.git,,而是Git ...

  10. PHP Warning: Module 'json' already loaded in Unknown on line 0

    Zend加密文件.启动服务器后无法正常运行加密后的文件.处理方法:   某台服务器上跑着php 5.3.8,线上服务运行正常. 某天拆分php错误日志时,发现其中有一段连续的错误信息. [14-Feb ...