选课系统中用到了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对象符合我的要求,便开始在我原来的代码上进行更改。最终实现了登录状态的保持。

最新文章

  1. jsp一句话
  2. JDom2的Xpath使用
  3. Linux下安装部署Java
  4. angular中$cacheFactory缓存的使用
  5. Python天猫淘宝评论爬虫
  6. 夺命雷公狗ThinkPHP项目之----企业网站15之文章删除的完成(单个)
  7. 2016年省赛G题, Parenthesis
  8. C3P0连接池使用小结
  9. Python interview preparing
  10. HDU 5025Saving Tang Monk BFS + 二进制枚举状态
  11. xfire调用webservice接口的实现方式
  12. JavaScript系列-----对象基于哈希存储(&lt;Key,Value&gt;之Key篇) (1)
  13. hadoop 1.0.1集群安装及配置
  14. [LOJ2310][APIO2017]斑斓之地——可持久化线段树
  15. 题解-CodeChef IOPC14L Sweets Problem
  16. [CocoaPods]使用Pod Lib创建
  17. 译 5. Spring使用JDBC访问关系数据
  18. 对java高级程序员有益的十本书
  19. JS设置cookie、读取cookie、删除cookie(转载)
  20. 洛谷 P5206: bzoj 5475: LOJ 2983: [WC2019] 数树

热门文章

  1. css技巧——垂直居中
  2. 从零学React Native之08Image组件
  3. Myeclipse 设置默认注释
  4. oracle函数 VSIZE(X)
  5. 【阿里云新品发布&#183;周刊】第13期:链路追踪 Tracing Analysis 商业化首发
  6. Oracle使用——varchar2() 和 char()关联查询 存在空格
  7. Java排序算法总结
  8. UTF-8与UTF-8 BOM
  9. 【codeforces 777E】Hanoi Factory
  10. 洛谷P4136 谁能赢呢? 题解 博弈论