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 ...
随机推荐
- Linux下如何切换用户
切换用户的命令为:su username 从普通用户切换到root用户,还可以使用命令:sudo su 在终端输入exit或logout或使用快捷方式ctrl+d,可以退回到原来用户,其实ctrl+d ...
- C++与JAVA代码实现CRC-16/MODBUS算法,且与 http://www.ip33.com/crc.html 进行结果验证
CRC-16/MODBUS的多项式为:x16+x15+x2+1(8005),宽度为16.运算时,首先将一个16位的寄存器预置为11111111 11111111,然后连续把数据帧中的每个字节中的8位与 ...
- CF1238E.Keyboard Purchase 题解 状压/子集划分DP
作者:zifeiy 标签:状压DP,子集划分DP 题目链接:https://codeforces.com/contest/1238/problem/E 题目大意: 给你一个长度为 \(n(n \le ...
- Redis源码解析:03字典
字典是一种用于保存键值对(key value pair)的抽象数据结构.在字典中,一个键和一个值进行关联,就是所谓的键值对.字典中的每个键都是独一无二的,可以根据键查找.更新值,或者删除整个键值对等等 ...
- Libev源码分析10:libev中poll的用例
在Libev中,使用poll作为backend时,涉及到下面几种数据结构: int *pollidxs; int pollidxmax; struct pollfd *polls; int pollm ...
- 最适合 Python 入门的资源有哪些?
https://blog.csdn.net/zV3e189oS5c0tSknrBCL/article/details/81230593 学习任何一门编程语言或者技能基本上都遵循3个步骤,第一步是看,第 ...
- <%@ include file=""%>与<jsp:include page=""/>两种方式的作用以及传值
一:使用 1.include指令: 1 <%@include file="文件的绝对路径或者相对路径"%> file属性是必填的(绝对或相对路径),但它不支持 ...
- linux 一些简单操作
vim ----三种模式 1.命令模式 2.输出模式 3.底线命令模式 w(e) 移动光标到下一个单词 b 移动到光标上一个单词 数字0 移动到本行开头 $ 移动光 ...
- 洛谷P1488 肥猫的游戏 题解 博弈论入门
题目链接:https://www.luogu.org/problem/P1488 其实这道题目我只需要 \(n\) 以及黑色三角形的三个端点编号就可以了. 我们假设在一个 \(n\) 边形中,黑色三角 ...
- [转]安卓加固之so文件加固
一.前言 最近在学习安卓加固方面的知识,看到了jiangwei212的博客,其中有对so文件加固的两篇文章通过节加密函数和通过hash段找到函数地址直接加密函数,感觉写的特别好,然后自己动手实践探索s ...