javaweb-选课系统
选课系统中用到了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-选课系统的更多相关文章
- 简单的JAVAWeb选课系统
该系统管理员可以添加和删除学生.教师,教师可以修改自己信息.添加课程.浏览自己课程,学生可以修改自己的信息.选课.浏览全部课程. 首先展示文件: 然后就是一次展示代码: Guanli包中代码: pac ...
- Javaweb实现简单的选课系统(主要技术包括jsp、Servlet、Javabean)
一.背景信息: 首先,这个选课系统是上周一老师在课堂上让我们做的测试,考试时长三个小时,我只做了一半,也没有实现选课流程. 由于上周忙于写实验报告没有时间继续完成这个测试.这周用前天和昨天一共七个小时 ...
- java web知识点复习,重新编写学生选课系统的先关操作。
为了复习之前学习的相关的html,javaweb等知识.自己有重新编写了一遍学生选课系统. 下面主要展示登录界面的代码,以及各个大的主页面的相关jsp. <%@ page language=&q ...
- 从零开始学Python06作业思路:学生选课系统
一,作业要求 选课系统: 管理员: 创建老师:姓名.性别.年龄.资产 创建课程:课程名称.上课时间.课时费.关联老师 学生:用户名.密码.性别.年龄.选课列表[].上课记录{课程1:[di,a,]} ...
- python之选课系统详解[功能未完善]
作业需求 思路:1.先写出大体的类,比如学校类,学生类,课程类-- 2.写出类里面大概的方法,比如学校类里面有创建讲师.创建班级-- 3.根据下面写出大致的代码,并实现其功能 遇到的困 ...
- Python开发程序:选课系统-改良版
程序名称: 选课系统 角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. ...
- python实现学生选课系统 面向对象的应用:
一.要求: 选课系统 管理员: 创建老师:姓名.性别.年龄.资产 创建课程:课程名称.上课时间.课时费.关联老师 使用pickle保存在文件 学生: 学生:用户名.密码.性别.年龄.选课列表[].上课 ...
- Python开发程序:选课系统
本节作业: 选课系统 角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. ...
- python 面向对象 class 老男孩选课系统
要求:1. 创建北京.上海 2 所学校 class2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. 课程包含,周期,价格,通过学校创建课 ...
- 一个简单的python选课系统
下面介绍一下自己写的python程序,主要是的知识点为sys.os.json.pickle的模块应用,python程序包的的使用,以及关于类的使用. 下面是我的程序目录: bin是存放一些执行文件co ...
随机推荐
- Python深入:Distutils发布Python模块
Distutils可以用来在Python环境中构建和安装额外的模块.新的模块可以是纯Python的,也可以是用C/C++写的扩展模块,或者可以是Python包,包中包含了由C和Python编写的模块. ...
- vscode golang vue配置
{ "files.autoSave": "off", "window.title": "${dirty}${activeEdito ...
- OpenStack组件系列☞glance搭建
第一步:glance关于数据库的操作 mysql -u root -p #登入数据库 CREATE DATABASE glance; #新建库keystone GRANT ALL PRIVILEGES ...
- 小程序中使用threejs
webgl调试 起初使用threejs 在小程序里面调试,明明是按着官方的文档来,但是会发现开发者工具上面会提示getContext,经过一翻摸索,发现webgl调试只能在手机端调试. 总结:webg ...
- Activiti5----流程监听器与任务监听器
首先创建流程监听器和任务监听器的实体类,个人比较喜欢使用Delegate Expression方式,其他两种方式也可以 流程监听器 package org.mpc.final_activiti; im ...
- 开源CMS比较
PHP-CMS的发展方向:简单,易用,美观 http://www.php-cms.cn/ 看点1,服务器一键安装,鼠标点点就搞定:输入数据库参数,在服务器上点一个按钮就完成全部的安装.简单配置一下网 ...
- H3C 以太网集线器
- [转载] CentOS系统开机自动挂载光驱 和 fstab文件详解
参考 http://blog.itpub.net/12272958/viewspace-676977/ 一.开机自动挂载光驱 1.按习惯,root用户,在/media目录下建立目录cdrom——mkd ...
- dotnet 设计规范 · 抽象定义
严格来说,只有一个类被其他的类继承,那么这个类就是基类.在很多时候,基类的定义是提供足够的抽象和通用方法和属性.默认实现.在继承关系中,基类定义在上层抽象和底层自定义之间. 他们充当抽象实现的实现帮助 ...
- Java中方法的格式
[修饰符] 返回值类型 方法名([参数类型 形式参数1,参数类型 形式参数2,……]) { 执行语句; [return 返回值;]//需要的话 } 参数列表(参数的类型 ...