基于javaweb+mysql的ssm考试在线报名管理系统(java+ssm+js+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM考试在线报名管理系统(java+ssm+js+jsp+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版本;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:HTML+CSS+JavaScript+jsp
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录
public class MessageUtil {
private static final String messageKey = "ActionMessage";
private static final String confirmMsg = "confirmMsg";
private static final String forwardUrlKey = "ForwardUrlKey";
private static final String callbackType = "callbackType";
private static final String navTabId = "navTabId";// rel="dlg_page"
public static void addCloseMessage(Map<String, Object> scope, String message) {
scope.put(messageKey, message);
scope.put(callbackType, "closeCurrent");
}
/**
* 关闭当前标签,刷新指定标签
* @param scope
* @param message 消息提示
* @param rel 刷新的标签ID
*/
public static void addCloseMessage(Map<String, Object> scope, String message,String rel) {
scope.put(messageKey, message);
scope.put(callbackType, "closeCurrent");
scope.put(navTabId, rel);
}
public static void addMessage(Map<String, Object> scope, String message) {
scope.put(messageKey, message);
}
public static void addMessage(Map<String, Object> scope, String message,
String rel) {
scope.put(messageKey, message);
if (StringUtil.isEmpty(rel)) {
scope.put(navTabId, "navTab");
} else {
scope.put(navTabId, rel);
}
}
public static void addRelMessage(HttpServletRequest scope, String message,
String rel) {
scope.setAttribute(messageKey, message);
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
}
package com.ssm.web.action;
@Controller
@RequestMapping("/sys")
public class OfficeAction extends BaseAction {
private String actionname = "教务办公室";
private String actionclass = "Office";
@Autowired
private OfficeService service;
@RequestMapping(value = "/add2Office.do")
public String add2() {
request.setAttribute("actionname", actionname);
request.setAttribute("actionclass", actionclass);
return "addOffice";
}
@RequestMapping(value = "/getOffice.do")
public String get(int uid) {
try {
Office bean = service.get(uid);
request.setAttribute("modifybean", bean);
request.setAttribute("actionname", actionname);
request.setAttribute("actionclass", actionclass);
return "modifyOffice";
} catch (Exception e) {
public String add(SimpleUser bean) {
try {
SimpleUser temp = simpleUserService.findByUname(bean.getUname());
if (temp != null) {
putSessionValue("signErrorMessage", "很遗憾,账号已经被使用.");
} else {
bean.setUserGender("男");
simpleUserService.addSimpleUser(bean);
putSessionValue("signErrorMessage", "恭喜您! 注册成功.");
}
} catch (Exception e) {
e.printStackTrace();
putSessionValue("signErrorMessage", "很遗憾,注册失败.");
}
return "redirect:/reg.jsp";
}
@RequestMapping(value = "/activeAccount.do")
public String activeAccount(int uid) {
try {
SimpleUser temp = simpleUserService.get(uid);
simpleUserService.updateActivity(temp);
session.setAttribute("signErrorMessage", "账号激活成功");
} catch (Exception e) {
e.printStackTrace();
session.setAttribute("signErrorMessage", "账号激活失败");
}
return "redirect:/index.jsp";
}
@RequestMapping(value = "/update2Password.do")
public String toSelf() {
return "msg/changepassword";
}
@RequestMapping(value = "/updateSysUserPassword.do")
public String updateSysUserPassword(String oldpassword, String password) {
SysUser user = getSysUser();
user = sysUserService.get(user.getId());
MD5 md = new MD5();
oldpassword = md.getMD5ofStr(oldpassword);
if (!user.getUserPassword().equals(oldpassword)) {
MessageUtil.addRelMessage(request, "操作成功.", "mainquery");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "操作失败.");
return ERROR;
}
}
@RequestMapping(value = "/addRoom.do")
public String add(Room bean) {
try {
service.add(bean);
MessageUtil.addMessage(request, "添加成功.");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "添加失败.");
return ERROR;
}
}
@RequestMapping(value = "/updateRoom.do")
public String update(Room bean) {
try {
service.update(bean);
MessageUtil.addMessage(request, "更新成功.");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "更新失败.");
return ERROR;
}
}
@RequestMapping(value = "/queryRoom.do")
public String query() {
try {
// 字段名称集合
LinkedList<String> parmnames = new LinkedList<String>();
// 字段值集合
LinkedList<Object> parmvalues = new LinkedList<Object>();
Page p = FieldUtil.createPage(request, Room.class, parmnames, parmvalues);
// if (parmnames.contains("type")) {
public class MessageUtil {
private static final String messageKey = "ActionMessage";
private static final String confirmMsg = "confirmMsg";
private static final String forwardUrlKey = "ForwardUrlKey";
private static final String callbackType = "callbackType";
private static final String navTabId = "navTabId";// rel="dlg_page"
public static void addCloseMessage(Map<String, Object> scope, String message) {
scope.put(messageKey, message);
scope.put(callbackType, "closeCurrent");
}
/**
* 关闭当前标签,刷新指定标签
* @param scope
* @param message 消息提示
* @param rel 刷新的标签ID
*/
public static void addCloseMessage(Map<String, Object> scope, String message,String rel) {
scope.put(messageKey, message);
scope.put(callbackType, "closeCurrent");
scope.put(navTabId, rel);
}
public static void addMessage(Map<String, Object> scope, String message) {
scope.put(messageKey, message);
}
public static void addMessage(Map<String, Object> scope, String message,
String rel) {
scope.put(messageKey, message);
if (StringUtil.isEmpty(rel)) {
scope.put(navTabId, "navTab");
} else {
scope.put(navTabId, rel);
}
}
public static void addRelMessage(HttpServletRequest scope, String message,
String rel) {
scope.setAttribute(messageKey, message);
if (StringUtil.isEmpty(rel)) {
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
}
package com.ssm.web.action;
@Controller
@RequestMapping("/sys")
public class ExamStudentAction extends BaseAction {
private String actionname = "报名";
// 判断是否有重复行
// 1.获取uniqueFields指定的列
if (uniqueFields != null) {
Cell[][] uniqueCells = new Cell[uniqueFields.length][];
for (int i = 0; i < uniqueFields.length; i++) {
int col = colMap.get(uniqueFields[i]);
uniqueCells[i] = sheet.getColumn(col);
}
// 2.从指定列中寻找重复行
for (int i = 1; i < realRows; i++) {
int nullCols = 0;
for (int j = 0; j < uniqueFields.length; j++) {
String currentContent = uniqueCells[j][i].getContents();
Cell sameCell = sheet.findCell(currentContent, uniqueCells[j][i].getColumn(), uniqueCells[j][i].getRow() + 1,
uniqueCells[j][i].getColumn(), uniqueCells[j][realRows - 1].getRow(), true);
if (sameCell != null) {
nullCols++;
}
}
if (nullCols == uniqueFields.length) {
throw new ExcelException("Excel中有重复行,请检查");
}
}
}
// 将sheet转换为list
for (int i = 1; i < realRows; i++) {
// 新建要转换的对象
T entity = entityClass.newInstance();
// 给对象中的字段赋值
for (Entry<String, String> entry : fieldMap.entrySet()) {
// 获取中文字段名
String cnNormalName = entry.getKey();
// 获取英文字段名
String enNormalName = entry.getValue();
// 根据中文字段名获取列号
int col = colMap.get(cnNormalName);
// 获取当前单元格中的内容
String content = sheet.getCell(col, i).getContents().toString().trim();
// 给对象赋值
setFieldValueByName(enNormalName, content, entity);
@RequestMapping(value = "/deleteRoom.do")
public String delete(String ids) {
try {
service.deleteAll(ids);
MessageUtil.addRelMessage(request, "操作成功.", "mainquery");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "操作失败.");
return ERROR;
}
}
@RequestMapping(value = "/addRoom.do")
public String add(Room bean) {
try {
service.add(bean);
MessageUtil.addMessage(request, "添加成功.");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "添加失败.");
return ERROR;
}
}
@RequestMapping(value = "/updateRoom.do")
public String update(Room bean) {
try {
service.update(bean);
MessageUtil.addMessage(request, "更新成功.");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "更新失败.");
return ERROR;
}
}
@RequestMapping(value = "/queryRoom.do")
public String query() {
try {
// 字段名称集合
LinkedList<String> parmnames = new LinkedList<String>();
// 字段值集合
LinkedList<Object> parmvalues = new LinkedList<Object>();
Page p = FieldUtil.createPage(request, Room.class, parmnames, parmvalues);
@Controller
@RequestMapping("/com")
public class LoginAction extends BaseAction {
@Autowired
private SysUserService sysUserService;
@Autowired
private SimpleUserService simpleUserService;
@Autowired
private TeacherService teacherService;
@RequestMapping(value = "/menu.do")
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "更新失败.");
return ERROR;
}
}
@RequestMapping(value = "/queryOffice.do")
public String query() {
try {
// 字段名称集合
LinkedList<String> parmnames = new LinkedList<String>();
// 字段值集合
LinkedList<Object> parmvalues = new LinkedList<Object>();
Page p = FieldUtil.createPage(request, Office.class, parmnames, parmvalues);
// if (parmnames.contains("type")) {
// actionname1 = (String) parmvalues.get(parmnames.indexOf("type"));
// }
Page page = service.selectPage(p, Office.class);
session.setAttribute(Constant.SESSION_PAGE, page);
request.setAttribute("actionname", actionname);
request.setAttribute("actionclass", actionclass);
return "listOffice";
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
}
package com.ssm.web.action;
@Controller
@RequestMapping("/sys")
public class ClazzAction extends BaseAction {
private String actionname = "班级";
private String actionclass = "Clazz";
e.printStackTrace();
// 如果是ExcelException,则直接抛出
if (e instanceof ExcelException) {
throw (ExcelException) e;
// 否则将其它异常包装成ExcelException再抛出
} else {
throw new ExcelException("导出Excel失败");
}
}
}
/**
* @MethodName : listToExcel
* @Description : 导出Excel(可以导出到本地文件系统,也可以导出到浏览器,工作表大小为2003支持的最大值)
* @param list
* 数据源
* @param fieldMap
* 类的英文属性和Excel中的中文列名的对应关系
* @param out
* 导出流
* @throws ExcelException
*/
public static <T> void listToExcel(List<T> list, LinkedHashMap<String, String> fieldMap, String sheetName, OutputStream out) throws ExcelException {
listToExcel(list, fieldMap, sheetName, 65535, out);
}
/**
* @MethodName : listToExcel
* @Description : 导出Excel(导出到浏览器,可以自定义工作表的大小)
* @param list
* 数据源
* @param fieldMap
* 类的英文属性和Excel中的中文列名的对应关系
* @param sheetSize
* 每个工作表中记录的最大个数
* @param response
* @param fieldName
* 字段名
* @param o
* 对象
* @return 字段值
*/
private static Object getFieldValueByName(String fieldName, Object o) throws Exception {
Object value = null;
Field field = getFieldByName(fieldName, o.getClass());
if (field != null) {
field.setAccessible(true);
value = field.get(o);
} else {
throw new ExcelException(o.getClass().getSimpleName() + "类不存在字段名 " + fieldName);
}
return value;
}
/**
* @MethodName : getFieldByName
* @Description : 根据字段名获取字段
* @param fieldName
* 字段名
* @param clazz
* 包含该字段的类
* @return 字段
*/
private static Field getFieldByName(String fieldName, Class<?> clazz) {
// 拿到本类的所有字段
Field[] selfFields = clazz.getDeclaredFields();
// 如果本类中存在该字段,则返回
for (Field field : selfFields) {
if (field.getName().equals(fieldName)) {
return field;
}
}
// 否则,查看父类中是否存在此字段,如果有则返回
Class<?> superClazz = clazz.getSuperclass();
if (superClazz != null && superClazz != Object.class) {
return getFieldByName(fieldName, superClazz);
}
// 如果本类和父类都没有,则返回空
try {
String code = (String) session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
if (code == null) {
request.getSession(false).invalidate();
return "redirect:/index.jsp";
} else {
}
checkcode = StringUtil.stringVerification(checkcode);
do {
if (!code.toLowerCase().equals(checkcode.toLowerCase())) {
errorMessage = "验证码错误";
break;
}
username = StringUtil.stringVerification(username).toLowerCase();
MD5 md = new MD5();
password = md.getMD5ofStr(password);
Object bean = sysUserService.login(username, password, loginType);
if (bean == null) {
errorMessage = "账号或者密码错误";
break;
}
SessionBean sb = new SessionBean();
sb.setUser(bean);
session.setAttribute(Constant.SESSION_BEAN, sb);
if (loginType.equals(SysUser.class.getSimpleName())) {
return "main";
}
if (loginType.equals(SimpleUser.class.getSimpleName())) {
SimpleUser temp = (SimpleUser) bean;
if (temp.getType().equals("未激活")) {
errorMessage = "账号未激活, 请登陆邮箱激活账号: " + temp.getUserEmail();
SpringMail sm = new SpringMail();
Mail m = new Mail();
m.setTitle("账号激活");
String content = "请点击下面的链接激活账号<br/><br/>";
String href = "http://localhost:8080/xs/com/activeAccount.do?uid=" + temp.getId();
content += "<a href=\"" + href + "\">" + "点击激活" + "<a>";
m.setContext(content);
m.setTo(temp.getUserEmail());
sm.sendMimeMail(m);
} else {
return "main";
}
}
if (loginType.equals(Teacher.class.getSimpleName())) {
return "main";
}
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "添加失败.");
return ERROR;
}
}
@RequestMapping(value = "/updateTeacher.do")
public String update(Teacher bean) {
try {
service.updateTeacher(bean);
MessageUtil.addMessage(request, "更新成功.");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "更新失败.");
return ERROR;
}
}
@RequestMapping(value = "/queryTeacher.do")
public String query() {
try {
// 字段名称集合
LinkedList<String> parmnames = new LinkedList<String>();
// 字段值集合
LinkedList<Object> parmvalues = new LinkedList<Object>();
Page p = FieldUtil.createPage(request, Teacher.class, parmnames, parmvalues);
// if (parmnames.contains("type")) {
// actionname1 = (String) parmvalues.get(parmnames.indexOf("type"));
// }
Page page = service.selectPage(p, Teacher.class);
session.setAttribute(Constant.SESSION_PAGE, page);
request.setAttribute("actionname", actionname);
request.setAttribute("actionclass", actionclass);
return "listTeacher";
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
}
package com.ssm.web.action;
}
}
@RequestMapping(value = "/addSysUser.do")
public String add(SysUser bean) {
try {
service.addSysUser(bean);
MessageUtil.addMessage(request, "添加成功.");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "添加失败.");
return ERROR;
}
}
@RequestMapping(value = "/updateSysUser.do")
public String update(SysUser bean) {
try {
service.updateSysUser(bean);
MessageUtil.addMessage(request, "更新成功.");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "更新失败.");
return ERROR;
}
}
@RequestMapping(value = "/querySysUser.do")
public String query() {
try {
// 字段名称集合
LinkedList<String> parmnames = new LinkedList<String>();
// 字段值集合
LinkedList<Object> parmvalues = new LinkedList<Object>();
Page p = FieldUtil.createPage(request, SysUser.class, parmnames, parmvalues);
// if (parmnames.contains("type")) {
// actionname1 = (String) parmvalues.get(parmnames.indexOf("type"));
// }
* @param url
*/
public static void addCloseMessages(Map<String, Object> scope,
String message, String url) {
scope.put(messageKey, message);
if (StringUtil.notEmpty(url)) {
scope.put(forwardUrlKey, url);
scope.put(callbackType, "closeCurrent");
}
}
public static void addMessage(HttpServletRequest scope, String message) {
scope.setAttribute(messageKey, message);
}
public static void addForwardUrl(HttpServletRequest scope, String url) {
if (StringUtil.notEmpty(url)) {
scope.setAttribute(forwardUrlKey, url);
scope.setAttribute(callbackType, "forward");
}
}
public static void addMessages(HttpServletRequest scope, String message,
String url) {
scope.setAttribute(messageKey, message);
addForwardUrl(scope, url);
}
public static void addRedirectMessages(HttpServletRequest scope, String message,
String url ) {
scope.setAttribute(messageKey, message);
if (StringUtil.notEmpty(url)) {
scope.setAttribute(forwardUrlKey, url);
scope.setAttribute(callbackType, "redirect");
}
}
public static void addConfirmMessages(Map<String, Object> scope, String message,
String url) {
scope.put(confirmMsg, message);
scope.put(forwardUrlKey, url);
scope.put(callbackType, "forwardConfirm");
}
public static void addConfirmMessages(Map<String, Object> scope, String message,
String url,String rel) {
scope.put(confirmMsg, message);
scope.put(forwardUrlKey, url);
scope.put(callbackType, "forwardConfirm");
if (StringUtil.isEmpty(rel)) {
scope.put(navTabId, "navTab");
@Controller
@RequestMapping("/sys")
public class TeacherAction extends BaseAction {
private String actionname = "考务管理员";
private String actionclass = "Teacher";
@Autowired
private TeacherService service;
@RequestMapping(value = "/add2Teacher.do")
public String add2() {
request.setAttribute("actionname", actionname);
request.setAttribute("actionclass", actionclass);
return "addTeacher";
}
@RequestMapping(value = "/getTeacher.do")
public String get(int uid) {
try {
Teacher bean = service.get(uid);
request.setAttribute("modifybean", bean);
request.setAttribute("actionname", actionname);
request.setAttribute("actionclass", actionclass);
return "modifyTeacher";
} catch (Exception e) {
e.printStackTrace();
MessageUtil.addMessage(request, "获取信息失败.");
return ERROR;
}
}
@RequestMapping(value = "/deleteTeacher.do")
public String delete(String ids) {
try {
service.deleteTeacher(ids);
MessageUtil.addRelMessage(request, "删除信息成功.", "mainquery");
return SUCCESS;
} catch (Exception e) {
// actionname1 = (String) parmvalues.get(parmnames.indexOf("type"));
// }
Page page = service.selectPage(p, SimpleUser.class);
session.setAttribute(Constant.SESSION_PAGE, page);
request.setAttribute("actionname", actionname);
request.setAttribute("actionclass", actionclass);
return "listSimpleUser";
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
}
package com.ssm.util;
public class MessageUtil {
private static final String messageKey = "ActionMessage";
private static final String confirmMsg = "confirmMsg";
private static final String forwardUrlKey = "ForwardUrlKey";
private static final String callbackType = "callbackType";
private static final String navTabId = "navTabId";// rel="dlg_page"
public static void addCloseMessage(Map<String, Object> scope, String message) {
scope.put(messageKey, message);
scope.put(callbackType, "closeCurrent");
}
/**
* 关闭当前标签,刷新指定标签
* @param scope
* @param message 消息提示
* @param rel 刷新的标签ID
*/
public static void addCloseMessage(Map<String, Object> scope, String message,String rel) {
scope.put(messageKey, message);
scope.put(callbackType, "closeCurrent");
scope.put(navTabId, rel);
}