基于javaweb+mysql的jsp+servlet在线学生选课管理系统(java+jsp+bootstrap+jquery+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet在线学生选课管理系统(java+jsp+bootstrap+jquery+servlet+mysql)
项目介绍
管理员角色包含以下功能: 管理员登录,学生管理,教师管理,班级管理,添加班级,添加教师,添加学生,课程管理,添加课程,系统用户管理,添加用户,修改密码等功能。
教师角色包含以下功能: 教师登录,选课管理,添加选课学生,成绩管理,添加成绩,查看学生信息,查看班级信息,查看个人档案,修改密码等功能。
学生角色包含以下功能: 学生登录,选课管理,成绩查看,查看个人档案,修改密码等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
技术栈
- 后端:servlet 2. 前端:JSP+bootstrap+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中db.properties与spring-mybatis.xml配置文件中的数据库配置改为自己的配置; 注:在spring-mybatis.xml没有将db.properties的数据同步过去的情况下修改; 4. 运行项目,输入localhost:8080/chaoshi 登录 注:tomcat中配置项目路径必须为/chaoshi,前端代码中已写死,否则会报错;
if(flag == -1){
str = "/admin/jiaoshi.jsp?mark="+mark;
request.setAttribute("message", "用户名或教师号重复!");
}else{
request.setAttribute("message", "操作成功!");
}
}
if(mark != null && mark.equals("update")){
str = "/admin/jiaoshi_list.jsp";
sql = "update jiaoshi set jiaoshihao='"+jiaoshihao+"',zhenname='"+zhenname+"',sex='"+sex+"',shengri='"+shengri+"',yuanxiao='"+yuanxiao+"',zhuanye='"+zhuanye+"',phone='"+phone+"',address='"+address+"',email='"+email+"' where id="+id;
int flag = ib.insertANDupdateANDdel(sql);
if(flag == -1){
str = "/admin/jiaoshi.jsp?mark="+mark+"&id="+id;
request.setAttribute("message", "教师号重复!");
}else{
request.setAttribute("message", "操作成功!");
}
}
RequestDispatcher rd=request.getRequestDispatcher(str);
rd.forward(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class BanjiServlet extends HttpServlet {
/**
s = m_application.getRealPath(s);
}
try
{
java.io.File file = new java.io.File(s);
FileOutputStream fileoutputstream = new FileOutputStream(file);
fileoutputstream.write(m_binArray);
fileoutputstream.close();
}
catch(Exception exception1)
{
throw new SmartUploadException("The Form cannot be saved in the specified file (1030).");
}
}
private boolean isVirtual(String s)
{
if(m_application.getRealPath(s) != null)
{
java.io.File file = new java.io.File(m_application.getRealPath(s));
return file.exists();
}
else
{
return false;
}
}
}
public class DelServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public DelServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
}
if(m_currentIndex == 1)
{
return;
}
for(m_currentIndex++;m_currentIndex < m_totalBytes;m_currentIndex = m_currentIndex + 2)
{
//long now=new java.util.Date().getTime();
String s1 = getDataHeader();
m_currentIndex = m_currentIndex + 2;
boolean flag3 = s1.indexOf("filename") > 0;
String s3 = getDataFieldValue(s1,"name");
if(flag3)
{
s6 = getDataFieldValue(s1,"filename");
s4 = getFileName(s6);
s5 = getFileExt(s4);
s7 = getContentType(s1);
s8 = getContentDisp(s1);
s9 = getTypeMIME(s7);
s10 = getSubTypeMIME(s7);
}
getDataSection();
if(flag3 && s4.length() > 0)
{
if(m_deniedFilesList.contains(s5))
{
throw new SecurityException("The extension of the file is denied to be uploaded (1015).");
}
if(!m_allowedFilesList.isEmpty() && !m_allowedFilesList.contains(s5))
{
throw new SecurityException("The extension of the file is not allowed to be uploaded (1010).");
}
if(m_maxFileSize > 0L && (long)((m_endData - m_startData) + 1) > m_maxFileSize)
{
throw new SecurityException("Size exceeded for this file : " + s4 + " (1105).");
}
l += (m_endData - m_startData) + 1;
if(m_totalMaxFileSize > 0L && l > m_totalMaxFileSize)
{
throw new SecurityException("Total File Size exceeded (1110).");
}
}
if(flag3)
{
SmartFile file = new SmartFile();
file.setParent(this);
file.setFieldName(s3);
file.setFileName(s4);
file.setFileExt(s5);
file.setFilePathName(s6);
}
return s1;
}
if(flag)
{
throw new IllegalArgumentException("The path is not a virtual path.");
}
else
{
throw new IllegalArgumentException("This path does not exist (1135).");
}
}
if(i == 2)
{
if(flag)
{
if(m_denyPhysicalPath)
{
throw new IllegalArgumentException("Physical path is denied (1125).");
}
else
{
return s;
}
}
if(isVirtual(s1))
{
throw new IllegalArgumentException("The path is not a physical path.");
}
else
{
throw new IllegalArgumentException("This path does not exist (1135).");
}
}
else
{
return null;
}
}
public void uploadInFile(String s) throws IOException,SmartUploadException
{
//boolean flag = false;
int i = 0;
int j = 0;
if(s == null)
{
throw new IllegalArgumentException("There is no specified destination file (1025).");
}
if(s.length() == 0)
}
private String getContentType(String s)
{
String s1 = ""; // = new String();
String s2 = ""; // = new String();
int i = 0;
//boolean flag = false;
s1 = "Content-Type:";
i = s.indexOf(s1) + s1.length();
if(i != -1)
{
int j = s.length();
s2 = s.substring(i,j);
}
return s2;
}
private String getTypeMIME(String s)
{
//String s1 = new String();
int i = 0;
i = s.indexOf("/");
if(i != -1)
{
return s.substring(1,i);
}
else
{
return s;
}
}
private String getSubTypeMIME(String s)
{
//String s1 = new String();
//boolean flag = false;
int i = 0;
i = s.indexOf("/") + 1;
if(i != -1)
{
int j = s.length();
return s.substring(i,j);
}
else
{
return s;
int j = 0;
i = s.indexOf(":") + 1;
j = s.indexOf(";");
s1 = s.substring(i,j);
return s1;
}
private void getDataSection()
{
//boolean flag = false;
//String s = "";
//String s = new String();
int i = m_currentIndex;
int j = 0;
int k = m_boundary.length();
m_startData = m_currentIndex;
m_endData = 0;
while(i < m_totalBytes)
{
if(m_binArray[i] == (byte)m_boundary.charAt(j))
{
if(j == k - 1)
{
m_endData = ((i - k) + 1) - 3;
break;
}
i++;
j++;
}
else
{
i++;
j = 0;
}
}
m_currentIndex = m_endData + k + 3;
}
private String getDataHeader()
{
//boolean flag = false;
int i = m_currentIndex;
int j = 0;
for(boolean flag1 = false;!flag1;)
//String s2 = ""; // = new String();
//boolean flag = false;
//boolean flag1 = false;
//boolean flag2 = false;
int i = 0;
i = s.lastIndexOf('/');
if(i != -1)
{
return s.substring(i + 1,s.length());
}
i = s.lastIndexOf('\\');
if(i != -1)
{
return s.substring(i + 1,s.length());
}
else
{
return s;
}
}
public void setDeniedFilesList(String s) throws ServletException,IOException,SQLException
{
//String s1 = "";
if(s != null)
{
String s2 = "";
for(int i = 0;i < s.length();i++)
{
if(s.charAt(i) == ',')
{
if(!m_deniedFilesList.contains(s2))
{
m_deniedFilesList.addElement(s2);
}
s2 = "";
}
else
{
s2 = s2 + s.charAt(i);
}
}
//if(s2 != "")
if(!s2.equals(""))
{
m_deniedFilesList.addElement(s2);
}
if(i == 1)
{
if(isVirtual(s1))
{
s1 = m_application.getRealPath(s1);
if(s1.endsWith(s3))
{
s1 = s1 + s2;
}
else
{
s1 = s1 + s3 + s2;
}
return s1;
}
if(flag)
{
throw new IllegalArgumentException("The path is not a virtual path.");
}
else
{
throw new IllegalArgumentException("This path does not exist (1135).");
}
}
if(i == 2)
{
if(flag)
{
if(m_denyPhysicalPath)
{
throw new IllegalArgumentException("Physical path is denied (1125).");
}
else
{
return s;
}
}
if(isVirtual(s1))
{
throw new IllegalArgumentException("The path is not a physical path.");
}
else
{
throw new IllegalArgumentException("This path does not exist (1135).");
}
}
else
private String getTypeMIME(String s)
{
//String s1 = new String();
int i = 0;
i = s.indexOf("/");
if(i != -1)
{
return s.substring(1,i);
}
else
{
return s;
}
}
private String getSubTypeMIME(String s)
{
//String s1 = new String();
//boolean flag = false;
int i = 0;
i = s.indexOf("/") + 1;
if(i != -1)
{
int j = s.length();
return s.substring(i,j);
}
else
{
return s;
}
}
private String getContentDisp(String s)
{
//String s1 = new String();
String s1 = "";
int i = 0;
int j = 0;
i = s.indexOf(":") + 1;
j = s.indexOf(";");
s1 = s.substring(i,j);
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
String sql = "";
String str = "";
InsertUpdateDelBean ib = new InsertUpdateDelBean();
AllBean ab = new AllBean();
String adminid = request.getParameter("adminid");
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
String pwd = request.getParameter("pwd");
String shenfen = request.getParameter("shenfen");
String sql = "";
String str = "";
sql = "select * from "+shenfen+" where name='"+name+"' and pwd='"+pwd+"'";
String args[] = {"id","name","pwd","shenfen"};
SelectBean sb = new SelectBean();
ArrayList al = sb.select(args, sql);
if(al == null || al.size() == 0){
str = "/index.jsp";
request.setAttribute("message", "用户名或密码错误!");
}else{
str = "/"+shenfen+"/modifypwd.jsp";
HttpSession session = request.getSession();
session.setAttribute("adminlogin", al);
session.setAttribute("shenfen", shenfen);
}
request.getRequestDispatcher(str).forward(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
m_totalBytes = 0;
m_currentIndex = 0;
m_startData = 0;
m_endData = 0;
m_boundary = ""; //new String();
m_totalMaxFileSize = 0L;
m_maxFileSize = 0L;
m_deniedFilesList = new Vector();
m_allowedFilesList = new Vector();
m_denyPhysicalPath = false;
//m_forcePhysicalPath = false;
m_contentDisposition = ""; //new String();
m_files = new SmartFiles();
m_formRequest = new SmartRequest();
}
/**
* @deprecated Method init is deprecated
*/
public final void init(ServletConfig servletconfig) throws ServletException
{
m_application = servletconfig.getServletContext();
}
/**
* @deprecated Method service is deprecated
*/
public void service(HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse) throws ServletException,IOException
{
m_request = httpservletrequest;
m_response = httpservletresponse;
}
public final void initialize(ServletConfig servletconfig,HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse) throws ServletException
{
m_application = servletconfig.getServletContext();
m_request = httpservletrequest;
m_response = httpservletresponse;
}
public final void initialize(PageContext pagecontext) throws ServletException
{
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
String mark = request.getParameter("mark");
String id = request.getParameter("id");
String name = request.getParameter("name");
String nianji = request.getParameter("nianji");
String banzhuren = request.getParameter("banzhuren");
String renshu = request.getParameter("renshu");
String shuoming = request.getParameter("shuoming");
String str = "";
String sql = "";
InsertUpdateDelBean ib = new InsertUpdateDelBean();
if(mark != null && mark.equals("add")){
str = "/admin/banji_list.jsp";
sql = "insert into banji(name,nianji,banzhuren,renshu,shuoming) values('"+name+"','"+nianji+"','"+banzhuren+"','"+renshu+"','"+shuoming+"')";
int flag = ib.insertANDupdateANDdel(sql);
if(flag == -1){
str = "/admin/banji.jsp?mark="+mark;
request.setAttribute("message", "班级名称重复!");
}else{
request.setAttribute("message", "操作成功!");
}
}
if(mark != null && mark.equals("update")){
{
throw new IllegalArgumentException("File '" + s + "' not found (1040).");
}
if(!isVirtual(s) && m_denyPhysicalPath)
{
throw new SecurityException("Physical path is denied (1035).");
}
if(isVirtual(s))
{
s = m_application.getRealPath(s);
}
java.io.File file = new java.io.File(s);
FileInputStream fileinputstream = new FileInputStream(file);
long l = file.length();
//boolean flag = false;
int k = 0;
byte abyte0[] = new byte[i];
if(s1 == null)
{
m_response.setContentType("application/x-msdownload");
}
else
{
if(s1.length() == 0)
{
m_response.setContentType("application/x-msdownload");
}
else
{
m_response.setContentType(s1);
}
}
m_response.setContentLength((int)l);
m_contentDisposition = m_contentDisposition != null ? m_contentDisposition : "attachment;";
if(s2 == null)
{
m_response.setHeader("Content-Disposition",m_contentDisposition + " filename=" + getFileName(s));
}
else
{
if(s2.length() == 0)
{
m_response.setHeader("Content-Disposition",m_contentDisposition);
}
else
{
m_response.setHeader("Content-Disposition",m_contentDisposition + " filename=" + s2);
}
}
while((long)k < l)
{
int j = fileinputstream.read(abyte0,0,i);
k += j;
m_response.getOutputStream().write(abyte0,0,j);
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
String mark = request.getParameter("mark");
String id = request.getParameter("id");
String name = request.getParameter("name");
String jiaoshi = request.getParameter("jiaoshi");
String keshi = request.getParameter("keshi");
String beizhu = request.getParameter("beizhu");
String str = "";
String sql = "";
InsertUpdateDelBean ib = new InsertUpdateDelBean();
if(mark != null && mark.equals("add")){
str = "/admin/kecheng_list.jsp";
sql = "insert into kecheng(name,jiaoshi,keshi,beizhu) values('"+name+"','"+jiaoshi+"','"+keshi+"','"+beizhu+"')";
int flag = ib.insertANDupdateANDdel(sql);
if(flag == -1){
str = "/admin/kecheng.jsp?mark="+mark;
request.setAttribute("message", "课程名称重复!");
}else{
request.setAttribute("message", "操作成功!");
}
}
if(mark != null && mark.equals("update")){
str = "/admin/kecheng_list.jsp";
sql = "update kecheng set name='"+name+"',jiaoshi='"+jiaoshi+"',keshi='"+keshi+"',beizhu='"+beizhu+"' where id="+id;
int flag = ib.insertANDupdateANDdel(sql);
if(flag == -1){
str = "/admin/kecheng.jsp?mark="+mark+"&id="+id;
request.setAttribute("message", "课程名称重复!");
}else{
request.setAttribute("message", "操作成功!");
}
request.setAttribute("message", "操作成功!");
}
}
RequestDispatcher rd=request.getRequestDispatcher(str);
rd.forward(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class BanjiServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public BanjiServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
String mark = request.getParameter("mark");
String id = request.getParameter("id");
String name = request.getParameter("name");
String pwd = request.getParameter("pwd");
String banji = request.getParameter("banji");
String xuehao = request.getParameter("xuehao");
String zhiwu = request.getParameter("zhiwu");
String zhenname = request.getParameter("zhenname");
String sex = request.getParameter("sex");
String shengri = request.getParameter("shengri");
String zuohao = request.getParameter("zuohao");
String shenfenzheng = request.getParameter("shenfenzheng");
String minzu = request.getParameter("minzu");
String jiguan = request.getParameter("jiguan");
String hukou = request.getParameter("hukou");
String address = request.getParameter("address");
String phone = request.getParameter("phone");
String email = request.getParameter("email");
String beizhu = request.getParameter("beizhu");
String str = "";
String sql = "";
InsertUpdateDelBean ib = new InsertUpdateDelBean();
if(mark != null && mark.equals("add")){
str = "/admin/xuesheng_list.jsp";
sql = "insert into xuesheng(name,pwd,banji,xuehao,zhiwu,zhenname,sex,shengri,zuohao,shenfenzheng,minzu,jiguan,hukou,address,phone,email,beizhu,shenfen) values('"+name+"','"+pwd+"','"+banji+"','"+xuehao+"','"+zhiwu+"','"+zhenname+"','"+sex+"','"+shengri+"','"+zuohao+"','"+shenfenzheng+"','"+minzu+"','"+jiguan+"','"+hukou+"','"+address+"','"+phone+"','"+email+"','"+beizhu+"','xuesheng')";
int flag = ib.insertANDupdateANDdel(sql);
if(flag == -1){
str = "/admin/xuesheng.jsp?mark="+mark;
request.setAttribute("message", "用户名或学号重复!");
}else{
request.setAttribute("message", "操作成功!");
}