基于SSH框架的学生考试系统(注意看文档目录)

                    基于SSH框架的学生考试系统

(1).先看一下我的目录结构
在这里插入图片描
(2).还有jsp文件目录
在这里插入图片描

在这里插入图片描述
(3).代码:(对应文件目录)
1.1
package com.ischoolbar.programmer.action;

import java.sql.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.ischoolbar.programmer.dao.ExamDao;
import com.ischoolbar.programmer.dao.QuestionDao;
import com.ischoolbar.programmer.model.Exam;
import com.ischoolbar.programmer.model.PageBean;
import com.ischoolbar.programmer.model.Question;
import com.ischoolbar.programmer.model.Student;
import com.ischoolbar.programmer.util.PageUtil;
import com.ischoolbar.programmer.util.PropertiesUtil;
import com.ischoolbar.programmer.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;

/**

  • 考试Action类
  • @author lizun

*/
public class ExamAction extends ActionSupport implements ServletRequestAware{

/**
 * 
 */
private static final long serialVersionUID = 1L;

private ExamDao examDao=new ExamDao();
private QuestionDao questionDao=new QuestionDao();

private HttpServletRequest request;

private String mainPage;

private Exam exam;
private Exam s_exam;

private List<Exam> examList;

private String page;
private int total;
private String pageCode;

public String getMainPage() {
	return mainPage;
}

public void setMainPage(String mainPage) {
	this.mainPage = mainPage;
}

public Exam getExam() {
	return exam;
}

public void setExam(Exam exam) {
	this.exam = exam;
}



public List<Exam> getExamList() {
	return examList;
}

public void setExamList(List<Exam> examList) {
	this.examList = examList;
}




public Exam getS_exam() {
	return s_exam;
}

public void setS_exam(Exam s_exam) {
	this.s_exam = s_exam;
}



public String getPage() {
	return page;
}

public void setPage(String page) {
	this.page = page;
}

public int getTotal() {
	return total;
}

public void setTotal(int total) {
	this.total = total;
}

public String getPageCode() {
	return pageCode;
}

public void setPageCode(String pageCode) {
	this.pageCode = pageCode;
}

/**
 * 计算/添加考试成绩
 * @return
 * @throws Exception
 */
public String add()throws Exception{
	Map<String, String[]> keyMap = new HashMap<String, String[]>();
    keyMap = request.getParameterMap();
    Iterator<Entry<String,String[]>> it2 = keyMap.entrySet().iterator();
    int totalScore=0;
    int singleScore=0;
    int moreScore=0;
    while (it2.hasNext()) {
        Entry<String, String[]> entry = it2.next();  
        String keyStr=entry.getKey();
        String values[]=entry.getValue();
        String key;
        String value="";
        if(keyStr.equals("exam.student.id")||keyStr.equals("exam.paper.id")){
        	continue;
        }
        if(keyStr.split("-")[1].equals("r")){  // 单选
        	key=keyStr.split("-")[2];
        	value=values[0];
        	singleScore+=this.calScore(key, value, "1");
        }else{  // 多选
        	key=keyStr.split("-")[2];
        	for(String s:values){
        		value+=s+",";
        	}
        	value=value.substring(0,value.length()-1);
        	moreScore+=this.calScore(key, value, "2");
        }
    }
    totalScore=singleScore+moreScore;
    exam.setSingleScore(singleScore);
    exam.setMoreScore(moreScore);
    exam.setScore(totalScore);
    exam.setExamDate(new Date(System.currentTimeMillis()));
    examDao.saveExam(exam);
	mainPage="exam/examResult.jsp";
	return SUCCESS;
}

/**
 * 计算每道题目的得分
 * @param questionId
 * @param userAnswer
 * @return
 */
private int calScore(String questionId,String userAnswer,String type)throws Exception{
	Question question=questionDao.getQuestion(questionId);
	if(userAnswer.equals(question.getAnswer())){
		if("1".equals(type)){
			return 20;
		}else{
			return 30;
		}
	}else{
		return 0;
	}
}

/**
 * 获取考试成绩
 * @return
 * @throws Exception
 */
public String getExams()throws Exception{
	examList=examDao.getExams(s_exam,null);
	mainPage="exam/myExam.jsp";
	return SUCCESS;
}

/**
 * 获取所有考试成绩
 * @return
 * @throws Exception
 */
public String examList()throws Exception{
	HttpSession session=request.getSession();
	if(StringUtil.isEmpty(page)){
		page="1";
	}
	if(s_exam!=null){
		session.setAttribute("s_exam", s_exam);
	}else{
		Object o=session.getAttribute("s_exam");
		if(o!=null){
			s_exam=(Exam)o;
		}else{
			s_exam=new Exam();
		}
	}
	PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(PropertiesUtil.getValue("pageSize")));
	examList=examDao.getExams(s_exam,pageBean);
	total=examDao.examCount(s_exam);
	pageCode=PageUtil.genPagation(request.getContextPath()+"/exam!examList",total, Integer.parseInt(page), Integer.parseInt(PropertiesUtil.getValue("pageSize")));
	mainPage="exam/examList.jsp";
	return SUCCESS;
}

public void setServletRequest(HttpServletRequest request) {
	this.request=request;
}

}

1.2

package com.ischoolbar.programmer.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.ischoolbar.programmer.dao.ManagerDao;
import com.ischoolbar.programmer.model.Manager;
import com.ischoolbar.programmer.model.Student;
import com.opensymphony.xwork2.ActionSupport;

public class ManagerAction extends ActionSupport implements ServletRequestAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private HttpServletRequest request;
	
	private ManagerDao managerDao=new ManagerDao();
	
	private Manager manager;
	private String error;
	
	public Manager getManager() {
		return manager;
	}

	public void setManager(Manager manager) {
		this.manager = manager;
	}
	

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	/**
	 * 登录验证
	 * @return
	 * @throws Exception
	 */
	public String login()throws Exception{
		HttpSession session=request.getSession();
		Manager currentUser=managerDao.login(manager);
		if(currentUser==null){
			error="用户名或者密码错误!";
			return ERROR;
		}else{
			session.setAttribute("currentUser", currentUser);
			return SUCCESS;
		}
	}
	
	/**
	 * 注销用户
	 * @throws Exception
	 */
	public String logout()throws Exception{
		request.getSession().invalidate();
		return "logout";
	}
	
	public void setServletRequest(HttpServletRequest request) {
		this.request=request;
	}

}

1.3

package com.ischoolbar.programmer.action;

import java.util.ArrayList;
import java.sql.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.ischoolbar.programmer.dao.PaperDao;
import com.ischoolbar.programmer.dao.QuestionDao;
import com.ischoolbar.programmer.model.Paper;
import com.ischoolbar.programmer.model.Question;
import com.ischoolbar.programmer.util.ResponseUtil;
import com.ischoolbar.programmer.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 试卷Action类
 * @author lizun
 *
 */
public class PaperAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private PaperDao paperDao=new PaperDao();
	private QuestionDao questionDao=new QuestionDao();
	
	private String mainPage;
	private String paperId;
	
	private List<Paper> paperList=new ArrayList<Paper>();
	private List<Question> squestionList=new ArrayList<Question>();
	private List<Question> mquestionList=new ArrayList<Question>();
	
	private String title; // 标题
	

	private Paper paper;
	
	public List<Paper> getPaperList() {
		return paperList;
	}

	public void setPaperList(List<Paper> paperList) {
		this.paperList = paperList;
	}
	
	

	public List<Question> getSquestionList() {
		return squestionList;
	}

	public void setSquestionList(List<Question> squestionList) {
		this.squestionList = squestionList;
	}

	public List<Question> getMquestionList() {
		return mquestionList;
	}

	public void setMquestionList(List<Question> mquestionList) {
		this.mquestionList = mquestionList;
	}

	public void setPaper(Paper paper) {
		this.paper = paper;
	}
	

	public Paper getPaper() {
		return paper;
	}

	

	public String getPaperId() {
		return paperId;
	}

	public void setPaperId(String paperId) {
		this.paperId = paperId;
	}

	public String getMainPage() {
		return mainPage;
	}

	public void setMainPage(String mainPage) {
		this.mainPage = mainPage;
	}

	
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * 获取所有试卷
	 * @return
	 * @throws Exception
	 */
	public String list()throws Exception{
		paperList=paperDao.getPapers();
		mainPage="exam/selectPaper.jsp";
		return SUCCESS;
	}
	
	/**
	 * 获取所有试卷(管理)
	 * @return
	 * @throws Exception
	 */
	public String paperList()throws Exception{
		paperList=paperDao.getPapers();
		mainPage="paper/paperList.jsp";
		return SUCCESS;
	}
	
	/**
	 * 通过id获取试卷实体
	 * @return
	 * @throws Exception
	 */
	public String getPaperById()throws Exception{
		paper=paperDao.getPaper(paperId);
		mainPage="paper/paperSave.jsp";
		return SUCCESS;
	}
	
	/**
	 * 保存预操作
	 * @return
	 * @throws Exception
	 */
	public String preSave()throws Exception{
		if(StringUtil.isNotEmpty(paperId)){
			paper=paperDao.getPaper(paperId);
			title="修改试卷";
		}else{
			title="添加试卷";
		}
		mainPage="paper/paperSave.jsp";
		return SUCCESS;
	}
	
	/**
	 * 保存试卷
	 * @return
	 * @throws Exception
	 */
	public String savePaper()throws Exception{
		if(StringUtil.isNotEmpty(paperId)){
			paper.setId(Integer.parseInt(paperId));
		}else{
			paper.setJoinDate(new Date(System.currentTimeMillis()));			
		}
		paperDao.savePaper(paper);
		return "save";
	}
	
	/**
	 * 删除试卷
	 * @return
	 * @throws Exception
	 */
	public String deletePaper()throws Exception{
		paper=paperDao.getPaper(paperId);
		JSONObject resultJson=new JSONObject();
		if(questionDao.existQuestionByPaperId(paperId)){
			resultJson.put("error","试卷下面有题目,不能删除");
		}else{
			paperDao.paperDelete(paper);
			resultJson.put("success",true);
		}
		ResponseUtil.write(resultJson,ServletActionContext.getResponse());
		return null;
	}
	
	/**
	 * 获取指定试卷
	 * @return
	 * @throws Exception
	 */
	public String getDetailPaper()throws Exception{
		paper=paperDao.getPaper(paperId);
		Set<Question> questionList=paper.getQuestions();
		Iterator<Question> it=questionList.iterator();
		while(it.hasNext()){
			Question q=it.next();
			if("1".equals(q.getType())){
				squestionList.add(q);
			}else{
				mquestionList.add(q);
			}
		}
		//squestionList=this.getRandomQuestion(squestionList, 3);
		//mquestionList=this.getRandomQuestion(mquestionList, 2);
		mainPage="exam/paper.jsp";
		return SUCCESS;
	}
	
	/**
	 * 获取随机试题
	 * @param questionList
	 * @param num
	 * @return
	 */
	private List<Question> getRandomQuestion(List<Question> questionList,int num){
		List<Question> resultList=new ArrayList<Question>();
		Random random=new Random();
		if(num>0){
			for(int i=1;i<=num;i++){
				int n=random.nextInt(questionList.size());
				Question q=questionList.get(n);
				if(resultList.contains(q)){
					i--;
				}else{
					resultList.add(questionList.get(n));					
				}
			}
		}
		return resultList;
	}

}

1.4:

package com.ischoolbar.programmer.action;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.ischoolbar.programmer.dao.PaperDao;
import com.ischoolbar.programmer.dao.QuestionDao;
import com.ischoolbar.programmer.model.PageBean;
import com.ischoolbar.programmer.model.Paper;
import com.ischoolbar.programmer.model.Question;
import com.ischoolbar.programmer.util.PageUtil;
import com.ischoolbar.programmer.util.PropertiesUtil;
import com.ischoolbar.programmer.util.ResponseUtil;
import com.ischoolbar.programmer.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;

public class QuestionAction extends ActionSupport implements ServletRequestAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private HttpServletRequest request;
	
	private QuestionDao questionDao=new QuestionDao();
	private PaperDao paperDao=new PaperDao();
	
	private List<Question> questionList;
	private List<Paper> paperList;
	private String mainPage;
	
	private String questionId;
	private Question question;
	private String title;
	
	private String page;
	private int total;
	private String pageCode;
	
	private Question s_question;
	
	

	public List<Paper> getPaperList() {
		return paperList;
	}

	public void setPaperList(List<Paper> paperList) {
		this.paperList = paperList;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List<Question> getQuestionList() {
		return questionList;
	}

	public void setQuestionList(List<Question> questionList) {
		this.questionList = questionList;
	}

	public String getMainPage() {
		return mainPage;
	}

	public void setMainPage(String mainPage) {
		this.mainPage = mainPage;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public String getPageCode() {
		return pageCode;
	}

	public void setPageCode(String pageCode) {
		this.pageCode = pageCode;
	}
	
	

	public Question getS_question() {
		return s_question;
	}

	public void setS_question(Question s_question) {
		this.s_question = s_question;
	}
	
	

	public String getQuestionId() {
		return questionId;
	}

	public void setQuestionId(String questionId) {
		this.questionId = questionId;
	}

	public Question getQuestion() {
		return question;
	}

	public void setQuestion(Question question) {
		this.question = question;
	}

	/**
	 * 查询试题信息
	 * @return
	 * @throws Exception
	 */
	public String list()throws Exception{
		HttpSession session=request.getSession();
		if(StringUtil.isEmpty(page)){
			page="1";
		}
		if(s_question!=null){
			session.setAttribute("s_question", s_question);
		}else{
			Object o=session.getAttribute("s_question");
			if(o!=null){
				s_question=(Question)o;
			}else{
				s_question=new Question();
			}
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(PropertiesUtil.getValue("pageSize")));
		questionList=questionDao.getQuestions(s_question,pageBean);
		total=questionDao.questionCount(s_question);
		pageCode=PageUtil.genPagation(request.getContextPath()+"/question!list",total, Integer.parseInt(page), Integer.parseInt(PropertiesUtil.getValue("pageSize")));
		mainPage="question/questionList.jsp";
		return SUCCESS;
	}
	
	/**
	 * 通过id获取试题
	 * @return
	 * @throws Exception
	 */
	public String getQuestionById()throws Exception{
		question=questionDao.getQuestion(questionId);
		mainPage="question/questionShow.jsp";
		return SUCCESS;
	}
	
	/**
	 * 预编辑操作
	 * @return
	 * @throws Exception
	 */
	public String preSave()throws Exception{
		paperList=paperDao.getPapers();
		if(StringUtil.isNotEmpty(questionId)){
			question=questionDao.getQuestion(questionId);
			title="修改试题信息";
		}else{
			title="添加试题信息";
		}
		mainPage="question/questionSave.jsp";
		return SUCCESS;
	}
	
	/**
	 * 删除试题
	 * @return
	 * @throws Exception
	 */
	public String delete()throws Exception{
		question=questionDao.getQuestion(questionId);
		questionDao.deleteQuestion(question);
		JSONObject resultJson=new JSONObject();
		resultJson.put("success",true);
		ResponseUtil.write(resultJson,ServletActionContext.getResponse());
		return null;
	}
	
	/**
	 * 保存试题
	 * @return
	 * @throws Exception
	 */
	public String saveQuestion()throws Exception{
		if(StringUtil.isNotEmpty(questionId)){
			question.setId(Integer.parseInt(questionId));
		}
		question.setAnswer(question.getAnswer().toUpperCase());
		questionDao.saveQuestion(question);
		return "save";
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request=request;
	}

}

1.5:

package com.ischoolbar.programmer.action;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.ischoolbar.programmer.dao.StudentDao;
import com.ischoolbar.programmer.model.PageBean;
import com.ischoolbar.programmer.model.Student;
import com.ischoolbar.programmer.util.DateUtil;
import com.ischoolbar.programmer.util.PageUtil;
import com.ischoolbar.programmer.util.PropertiesUtil;
import com.ischoolbar.programmer.util.ResponseUtil;
import com.ischoolbar.programmer.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 学生Action类
 * @author Administrator
 *
 */
public class StudentAction extends ActionSupport implements ServletRequestAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private StudentDao studentDao=new StudentDao();
	private HttpServletRequest request;
	
	private String mainPage;
	
	private Student student;
	private String error;
	
	private String page;
	private int total;
	private String pageCode;
	
	private List<Student> studentList;
	
	private Student s_student;
	
	private String id;  // 学生编号
	
	private String title; // 标题
	
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
	public String getError() {
		return error;
	}
	public void setError(String error) {
		this.error = error;
	}
	
	public String getMainPage() {
		return mainPage;
	}
	public void setMainPage(String mainPage) {
		this.mainPage = mainPage;
	}
	
	
	
	
	public String getPageCode() {
		return pageCode;
	}
	public void setPageCode(String pageCode) {
		this.pageCode = pageCode;
	}
	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public Student getS_student() {
		return s_student;
	}
	public void setS_student(Student s_student) {
		this.s_student = s_student;
	}
	public List<Student> getStudentList() {
		return studentList;
	}
	public void setStudentList(List<Student> studentList) {
		this.studentList = studentList;
	}
	
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	/**
	 * 登录验证
	 * @return
	 * @throws Exception
	 */
	public String login()throws Exception{
		HttpSession session=request.getSession();
		Student currentUser=studentDao.login(student);
		if(currentUser==null){
			error="准考证号或者密码错误!";
			return ERROR;
		}else{
			session.setAttribute("currentUser", currentUser);
			return SUCCESS;
		}
	}
	
	/**
	 * 修改密码预操作
	 * @return
	 * @throws Exception
	 */
	public String preUpdatePassword()throws Exception{
		mainPage="student/updatePassword.jsp";
		return SUCCESS;
	}
	
	/**
	 * 修改密码
	 * @return
	 * @throws Exception
	 */
	public String updatePassword()throws Exception{
		Student s=studentDao.getStudentById(student.getId());
		s.setPassword(student.getPassword());
		studentDao.saveStudent(s);
		mainPage="student/updateSuccess.jsp";
		return SUCCESS;
	}
	
	/**
	 * 查询学生信息
	 * @return
	 * @throws Exception
	 */
	public String list()throws Exception{
		HttpSession session=request.getSession();
		if(StringUtil.isEmpty(page)){
			page="1";
		}
		if(s_student!=null){
			session.setAttribute("s_student", s_student);
		}else{
			Object o=session.getAttribute("s_student");
			if(o!=null){
				s_student=(Student)o;
			}else{
				s_student=new Student();
			}
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(PropertiesUtil.getValue("pageSize")));
		studentList=studentDao.getStudents(s_student,pageBean);
		total=studentDao.studentCount(s_student);
		pageCode=PageUtil.genPagation(request.getContextPath()+"/student!list",total, Integer.parseInt(page), Integer.parseInt(PropertiesUtil.getValue("pageSize")));
		mainPage="student/studentList.jsp";
		return SUCCESS;
	}
	
	/**
	 * 获取学生
	 * @return
	 * @throws Exception
	 */
	public String getStudentById()throws Exception{
		student=studentDao.getStudent(id);
		mainPage="student/studentSave.jsp";
		return SUCCESS;
	}
	
	/**
	 * 保存学生
	 * @return
	 * @throws Exception
	 */
	public String saveStudent()throws Exception{
		if(StringUtil.isEmpty(student.getId())){
			student.setId("JS"+DateUtil.getCurrentDateStr());			
		}
		studentDao.saveStudent(student);
		return "save";
	}
	
	/**
	 * 删除学生
	 * @return
	 * @throws Exception
	 */
	public String deleteStudent()throws Exception{
		student=studentDao.getStudent(id);
		studentDao.studentDelete(student);
		JSONObject resultJson=new JSONObject();
		resultJson.put("success",true);
		ResponseUtil.write(resultJson,ServletActionContext.getResponse());
		return null;
	}
	
	/**
	 * 预添加操作
	 * @return
	 * @throws Exception
	 */
	public String preSave()throws Exception{
		if(StringUtil.isNotEmpty(id)){
			student=studentDao.getStudent(id);
			title="修改学生信息";
		}else{
			title="添加学生信息";
		}
		mainPage="student/studentSave.jsp";
		return SUCCESS;
	}
	
	/**
	 * 注销用户
	 * @throws Exception
	 */
	public String logout()throws Exception{
		request.getSession().invalidate();
		return "logout";
	}
	
	public void setServletRequest(HttpServletRequest request) {
		this.request=request;
	}
	


}

2.1:

package com.ischoolbar.programmer.dao;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.ischoolbar.programmer.model.Exam;
import com.ischoolbar.programmer.model.PageBean;
import com.ischoolbar.programmer.util.HibernateUtil;
import com.ischoolbar.programmer.util.StringUtil;

/**
 * 考试DAO类
 * @author Administrator
 *
 */
public class ExamDao {

	/**
	 * 保存考试信息
	 * @param exam
	 * @throws Exception
	 */
	public void saveExam(Exam exam)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.merge(exam);
		session.getTransaction().commit();
	}
	
	/**
	 * 获取考试信息
	 * @return
	 * @throws Exception
	 */
	public List<Exam> getExams(Exam s_exam,PageBean pageBean)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StringBuffer hql=new StringBuffer("from Exam exam");
		if(s_exam.getStudent()!=null&&StringUtil.isNotEmpty(s_exam.getStudent().getId())){
			hql.append(" and exam.student.id like '%"+s_exam.getStudent().getId()+"%'");
		}
		if(s_exam.getStudent()!=null&&StringUtil.isNotEmpty(s_exam.getStudent().getName())){
			hql.append(" and exam.student.name like '%"+s_exam.getStudent().getName()+"%'");
		}
		Query query=session.createQuery(hql.toString().replaceFirst("and", "where"));
		if(pageBean!=null){
			query.setFirstResult(pageBean.getStart());
			query.setMaxResults(pageBean.getPageSize());
		}
		@SuppressWarnings("unchecked")
		List<Exam> examList=(List<Exam>)query.list();
		session.getTransaction().commit();
		return examList;
	}
	
	/**
	 * 查询考试信息记录数
	 * @param s_exam
	 * @return
	 * @throws Exception
	 */
	public int examCount(Exam s_exam)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StringBuffer sql=new StringBuffer("select count(*) from t_exam t1 ,t_student t2 where t1.studentId=t2.id ");
		if(s_exam.getStudent()!=null&&StringUtil.isNotEmpty(s_exam.getStudent().getId())){
			sql.append(" and t2.id like '%"+s_exam.getStudent().getId()+"%'");
		}
		if(s_exam.getStudent()!=null&&StringUtil.isNotEmpty(s_exam.getStudent().getName())){
			sql.append(" and t2.name like '%"+s_exam.getStudent().getName()+"%'");
		}
		Query query=session.createSQLQuery(sql.toString());
		int count=((BigInteger)query.uniqueResult()).intValue();
		session.getTransaction().commit();
		return count;
	}
}

2.2:

package com.ischoolbar.programmer.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import com.ischoolbar.programmer.model.Manager;
import com.ischoolbar.programmer.util.HibernateUtil;

/**
 * 管理员DAO类
 * @author lizun
 *
 */
public class ManagerDao {

	/**
	 * 管理员登录验证
	 * @param student
	 * @return
	 * @throws Exception
	 */
	public Manager login(Manager manager)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Query query=session.createQuery("from Manager as m where m.userName=:userName and m.password=:password ");
		query.setString("userName", manager.getUserName());
		query.setString("password", manager.getPassword());
		Manager resultManager=(Manager)query.uniqueResult();
		session.getTransaction().commit();
		return resultManager;
	}
}

2.3:

package com.ischoolbar.programmer.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.ischoolbar.programmer.model.Paper;
import com.ischoolbar.programmer.util.HibernateUtil;

/**
 * 试卷DAO类
 * @author 
 *
 */
public class PaperDao {

	/**
	 * 获取所有试卷
	 * @return
	 * @throws Exception
	 */
	public List<Paper> getPapers()throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Query query=session.createQuery("from Paper");
		@SuppressWarnings("unchecked")
		List<Paper> paperList=(List<Paper>)query.list();
		session.getTransaction().commit();
		return paperList;
	}
	
	/**
	 * 获取指定试卷
	 * @param paperId
	 * @return
	 * @throws Exception
	 */
	public Paper getPaper(String paperId)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Paper paper=(Paper)session.get(Paper.class, Integer.parseInt(paperId));
		session.getTransaction().commit();
		return paper;
	}
	
	/**
	 * 保存试卷实体
	 * @param paper
	 * @throws Exception
	 */
	public void savePaper(Paper paper)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.merge(paper);
		session.getTransaction().commit();
	}
	
	/**
	 * 删除试卷
	 * @param paper
	 * @throws Exception
	 */
	public void paperDelete(Paper paper)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.delete(paper);
		session.getTransaction().commit();
	}
}

2.4:

package com.ischoolbar.programmer.dao;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.ischoolbar.programmer.model.PageBean;
import com.ischoolbar.programmer.model.Question;
import com.ischoolbar.programmer.model.Student;
import com.ischoolbar.programmer.util.HibernateUtil;
import com.ischoolbar.programmer.util.StringUtil;

/**
 * 问题DAO类
 * @author lizun
 *
 */
public class QuestionDao {

	/**
	 * 通过问题id获取问题实体
	 * @param questionId
	 * @return
	 * @throws Exception
	 */
	public Question getQuestion(String questionId)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Question question=(Question) session.get(Question.class, Integer.parseInt(questionId));
		session.getTransaction().commit();
		return question;
	}
	
	/**
	 * 判断执行的试卷下有无题目
	 * @param paperId
	 * @return
	 * @throws Exception
	 */
	public boolean existQuestionByPaperId(String paperId)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Query query=session.createQuery("from Question as q where q.paper.id=:paperId");
		query.setString("paperId", paperId);
		@SuppressWarnings("unchecked")
		List<Student> studentList=(List<Student>)query.list();
		session.getTransaction().commit();
		if(studentList.size()>0){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 获取所有题目
	 * @param s_question
	 * @param pageBean
	 * @return
	 * @throws Exception
	 */
	public List<Question> getQuestions(Question s_question,PageBean pageBean)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StringBuffer hql=new StringBuffer("from Question");
		if(StringUtil.isNotEmpty(s_question.getSubject())){
			hql.append(" and subject like '%"+s_question.getSubject()+"%'");
		}
		Query query=session.createQuery(hql.toString().replaceFirst("and", "where"));
		if(pageBean!=null){
			query.setFirstResult(pageBean.getStart());
			query.setMaxResults(pageBean.getPageSize());
		}
		@SuppressWarnings("unchecked")
		List<Question> questionList=(List<Question>)query.list();
		session.getTransaction().commit();
		return questionList;
	}
	
	/**
	 * 查询试题记录数
	 * @param s_question
	 * @return
	 * @throws Exception
	 */
	public int questionCount(Question s_question)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StringBuffer sql=new StringBuffer("select count(*) from t_question");
		if(StringUtil.isNotEmpty(s_question.getSubject())){
			sql.append(" and subject like '%"+s_question.getSubject()+"%'");
		}
		Query query=session.createSQLQuery(sql.toString().replaceFirst("and", "where"));
		int count=((BigInteger)query.uniqueResult()).intValue();
		session.getTransaction().commit();
		return count;
	}
	

	
	/**
	 * 保存试题实体
	 * @param question
	 * @throws Exception
	 */
	public void saveQuestion(Question question)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.merge(question);
		session.getTransaction().commit();
	}
	
	/**
	 * 删除试题
	 * @param question
	 * @throws Exception
	 */
	public void deleteQuestion(Question question)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.delete(question);
		session.getTransaction().commit();
	}
}

2.5:

package com.ischoolbar.programmer.dao;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.ischoolbar.programmer.model.PageBean;
import com.ischoolbar.programmer.model.Student;
import com.ischoolbar.programmer.util.HibernateUtil;
import com.ischoolbar.programmer.util.StringUtil;

/**
 * 学生DAO类
 * @author lizun
 *
 */
public class StudentDao {

	/**
	 * 学生登录
	 * @param student
	 * @return
	 * @throws Exception
	 */
	public Student login(Student student)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Query query=session.createQuery("from Student as s where s.id=:id and s.password=:password ");
		query.setString("id", student.getId());
		query.setString("password", student.getPassword());
		Student resultStu=(Student)query.uniqueResult();
		session.getTransaction().commit();
		return resultStu;
	}
	
	/**
	 * 通过id获取学生实体
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Student getStudentById(String id)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Student student=(Student)session.get(Student.class, id);
		session.getTransaction().commit();
		return student;
	}
	
	/**
	 * 保存学生实体
	 * @param student
	 * @throws Exception
	 */
	public void saveStudent(Student student)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.merge(student);
		session.getTransaction().commit();
	}
	
	/**
	 * 获取所有学生
	 * @return
	 * @throws Exception
	 */
	public List<Student> getStudents(Student s_student,PageBean pageBean)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StringBuffer hql=new StringBuffer("from Student");
		if(StringUtil.isNotEmpty(s_student.getId())){
			hql.append(" and id like '%"+s_student.getId()+"%'");
		}
		if(StringUtil.isNotEmpty(s_student.getName())){
			hql.append(" and name like '%"+s_student.getName()+"%'");
		}
		Query query=session.createQuery(hql.toString().replaceFirst("and", "where"));
		if(pageBean!=null){
			query.setFirstResult(pageBean.getStart());
			query.setMaxResults(pageBean.getPageSize());
		}
		@SuppressWarnings("unchecked")
		List<Student> studentList=(List<Student>)query.list();
		session.getTransaction().commit();
		return studentList;
	}
	
	/**
	 * 查询学生记录数
	 * @param s_student
	 * @return
	 * @throws Exception
	 */
	public int studentCount(Student s_student)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StringBuffer sql=new StringBuffer("select count(*) from t_student");
		if(StringUtil.isNotEmpty(s_student.getId())){
			sql.append(" and id like '%"+s_student.getId()+"%'");
		}
		if(StringUtil.isNotEmpty(s_student.getName())){
			sql.append(" and name like '%"+s_student.getName()+"%'");
		}
		Query query=session.createSQLQuery(sql.toString().replaceFirst("and", "where"));
		int count=((BigInteger)query.uniqueResult()).intValue();
		session.getTransaction().commit();
		return count;
	}
	
	/**
	 * 保存学生
	 * @param student
	 * @throws Exception
	 */
	public void studentSave(Student student)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.merge(student);
		session.getTransaction().commit();
	}
	
	/**
	 * 删除学生
	 * @param student
	 * @throws Exception
	 */
	public void studentDelete(Student student)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.delete(student);
		session.getTransaction().commit();
	}
	
	/**
	 * 通过id获取学生
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Student getStudent(String id)throws Exception{
		Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Student student=(Student) session.get(Student.class, id);
		session.getTransaction().commit();
		return student;
	}
}

3.1:

package com.ischoolbar.programmer.model;

import java.sql.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/**
 * 考试表
 * @author Administrator
 *
 */
@Entity
@Table(name="t_exam")
public class Exam {

	private int id;  // 考试编号
	private Student student; // 学生
	private Paper paper; // 试卷
	private int singleScore; // 单选题得分
	private int moreScore; // 多选题得分
	private int score;  // 总得分
	private Date examDate; // 考试时间
	
	@Id
	@GeneratedValue(generator="_native")
	@GenericGenerator(name="_native",strategy="native")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@ManyToOne
	@JoinColumn(name="studentId")
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
	
	@ManyToOne
	@JoinColumn(name="paperId")
	public Paper getPaper() {
		return paper;
	}
	public void setPaper(Paper paper) {
		this.paper = paper;
	}
	public int getScore() {
		return score;
	}
	public void setScore(int score) {
		this.score = score;
	}
	public Date getExamDate() {
		return examDate;
	}
	public void setExamDate(Date examDate) {
		this.examDate = examDate;
	}
	public int getSingleScore() {
		return singleScore;
	}
	public void setSingleScore(int singleScore) {
		this.singleScore = singleScore;
	}
	public int getMoreScore() {
		return moreScore;
	}
	public void setMoreScore(int moreScore) {
		this.moreScore = moreScore;
	}
	
	
}

3.2:

package com.ischoolbar.programmer.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

/**
 * 管理员类
 * @author Administrator
 *
 */
@Entity
@Table(name="t_manager")
public class Manager {

	private int id; // 编号
	private String userName; // 用户名
	private String password; // 密码
	private String name; // 名字
	private String flag="1";
	
	@Id
	@GeneratedValue(generator="_native")
	@GenericGenerator(name="_native",strategy="native")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Transient
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	
	
	
	
}

3.3:

package com.ischoolbar.programmer.model;

/**
 * 分页Model类
 * @author 
 *
 */
public class PageBean {

	private int page; // 第几页
	private int pageSize; // 每页记录数
	private int start;  // 起始页
	
	
	public PageBean(int page, int pageSize) {
		super();
		this.page = page;
		this.pageSize = pageSize;
	}
	
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getStart() {
		return (page-1)*pageSize;
	}
	
	
}

3.4:

package com.ischoolbar.programmer.model;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/**
 * 试卷表
 * @author Administrator
 *
 */
@Entity
@Table(name="t_paper")
public class Paper {

	private int id;
	private String paperName;
	private Date joinDate;
	private Set<Question> questions=new HashSet<Question>();
	
	@Id
	@GeneratedValue(generator="_native")
	@GenericGenerator(name="_native",strategy="native")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public String getPaperName() {
		return paperName;
	}
	public void setPaperName(String paperName) {
		this.paperName = paperName;
	}
	public Date getJoinDate() {
		return joinDate;
	}
	public void setJoinDate(Date joinDate) {
		this.joinDate = joinDate;
	}
	@OneToMany(mappedBy="paper",fetch=FetchType.EAGER)
	public Set<Question> getQuestions() {
		return questions;
	}
	public void setQuestions(Set<Question> questions) {
		this.questions = questions;
	}
	
	
}

3.5:

package com.ischoolbar.programmer.model;

import java.sql.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;

/**
 * 题目表
 * @author Administrator
 *
 */
@Entity
@Table(name="t_question")
public class Question {

	private int id;  // 问题编号
	private String subject; // 题目名称
	private String type; // 题目类型 1 是单选题 2 是多选题
	private Date joinTime; // 添加时间
	
	private Paper paper; // 试卷
	
	private String optionA; // 选项A
	private String optionB; // 选项B
	private String optionC; // 选项C
	private String optionD; // 选项D
	private String answer; // 答案
	
	private String userAnswer; // 用户回答
	
	@Id
	@GeneratedValue(generator="_native")
	@GenericGenerator(name="_native",strategy="native")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Date getJoinTime() {
		return joinTime;
	}
	public void setJoinTime(Date joinTime) {
		this.joinTime = joinTime;
	}
	@ManyToOne
	@Cascade(value={CascadeType.SAVE_UPDATE})
	@JoinColumn(name="paperId")
	public Paper getPaper() {
		return paper;
	}
	public void setPaper(Paper paper) {
		this.paper = paper;
	}
	public String getOptionA() {
		return optionA;
	}
	public void setOptionA(String optionA) {
		this.optionA = optionA;
	}
	public String getOptionB() {
		return optionB;
	}
	public void setOptionB(String optionB) {
		this.optionB = optionB;
	}
	public String getOptionC() {
		return optionC;
	}
	public void setOptionC(String optionC) {
		this.optionC = optionC;
	}
	public String getOptionD() {
		return optionD;
	}
	public void setOptionD(String optionD) {
		this.optionD = optionD;
	}
	public String getAnswer() {
		return answer;
	}
	public void setAnswer(String answer) {
		this.answer = answer;
	}
	
	@Transient
	public String getUserAnswer() {
		return userAnswer;
	}
	public void setUserAnswer(String userAnswer) {
		this.userAnswer = userAnswer;
	}
	
	
	
}

3.6:

package com.ischoolbar.programmer.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.ischoolbar.programmer.util.HibernateUtil;

@Entity
@Table(name="t_student")
public class Student {

	private String id; // 编号、准考证
	private String name; // 姓名
	private String password; // 密码
	private String sex; // 性别
	private String prefession; // 专业
	private String cardNo; // 身份证
	
	private String flag="2"; // 用户类型  1:管理员  2:考生
	
	@Id
	@Column(name = "id", unique = true, nullable = false,length=40)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	@Column(name = "name",length=20)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name = "password",length=20)
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	@Column(name = "sex",length=5)
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	@Column(name = "prefession",length=40)
	public String getPrefession() {
		return prefession;
	}
	public void setPrefession(String prefession) {
		this.prefession = prefession;
	}
	
	@Column(name = "cardNo",length=50)
	public String getCardNo() {
		return cardNo;
	}
	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}
	@Transient
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	
}

4.1:

package com.ischoolbar.programmer.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.ischoolbar.programmer.util.HibernateUtil;

public class Test {

	public static void main(String[] args) {
		SessionFactory sessionFactory=HibernateUtil.getSessionFactory();
		Session session=sessionFactory.openSession(); // 生成一个session
	    session.beginTransaction(); // 开启事务
	    
	   
	    
	    session.getTransaction().commit(); // 提交事务
	    session.close(); // 关闭session
	}
}

5.1:

package com.ischoolbar.programmer.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	public static String formatDate(Date date,String format){
		String result="";
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		if(date!=null){
			result=sdf.format(date);
		}
		return result;
	}
	
	
	public static Date formatString(String str,String format) throws Exception{
		if(StringUtil.isEmpty(str)){
			return null;
		}
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		return sdf.parse(str);
	}
	
	public static String getCurrentDateStr()throws Exception{
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmss");
		return sdf.format(date);
	}
}

5.2:

package com.ischoolbar.programmer.util;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

/**
 * Hibernate工厂类
 * @author Administrator
 *
 */
public class HibernateUtil {

	private static final SessionFactory sessionFactory = buildSessionFactory();

	/**
	 * 获取静态工厂
	 * @return
	 */
    private static SessionFactory buildSessionFactory() {
    	Configuration configuration = new Configuration().configure();
		ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
		return configuration.buildSessionFactory(serviceRegistry);
    }

    /**
     * 获取session工厂
     * @return
     */
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

5.3:

package com.ischoolbar.programmer.util;

public class PageUtil {


	
	public static String genPagation(String targetUrl,int totalNum,int currentPage,int pageSize){
		int totalPage=totalNum%pageSize==0?totalNum/pageSize:totalNum/pageSize+1;
		StringBuffer pageCode=new StringBuffer();
		pageCode.append("<li><a href='"+targetUrl+"?page=1'>首页</a></li>");
		if(currentPage==1){
			pageCode.append("<li class='disabled'><a href='#'>上一页</a></li>");			
		}else{
			pageCode.append("<li><a href='"+targetUrl+"?page="+(currentPage-1)+"'>上一页</a></li>");			
		}
		for(int i=currentPage-2;i<=currentPage+2;i++){
			if(i<1||i>totalPage){
				continue;
			}
			if(i==currentPage){
				pageCode.append("<li class='active'><a href='#'>"+i+"</a></li>");		
			}else{
				pageCode.append("<li><a href='"+targetUrl+"?page="+i+"'>"+i+"</a></li>");	
			}
		}
		if(currentPage==totalPage){
			pageCode.append("<li class='disabled'><a href='#'>下一页</a></li>");			
		}else{
			pageCode.append("<li><a href='"+targetUrl+"?page="+(currentPage+1)+"'>下一页</a></li>");		
		}
		pageCode.append("<li><a href='"+targetUrl+"?page="+totalPage+"'>尾页</a></li>");
		return pageCode.toString();
	}
}

5.4:

package com.ischoolbar.programmer.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {

	public static String getValue(String key){
		Properties prop = new Properties();
		InputStream in = new PropertiesUtil().getClass().getResourceAsStream("/exam.properties");
		try {
			prop.load(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return (String)prop.get(key);
	}
	
	
}

5.5:

package com.ischoolbar.programmer.util;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;


public class ResponseUtil {

	public static void write(Object o,HttpServletResponse response)throws Exception{
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=response.getWriter();
		out.println(o.toString());
		out.flush();
		out.close();
	}
}

5.6:

package com.ischoolbar.programmer.util;

/**
 * 字符串工具类
 * @author 
 *
 */
public class StringUtil {

	/**
	 * 判断是否是空
	 * @param str
	 * @return
	 */
	public static boolean isEmpty(String str){
		if("".equals(str)|| str==null){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 判断是否不是空
	 * @param str
	 * @return
	 */
	public static boolean isNotEmpty(String str){
		if(!"".equals(str)&&str!=null){
			return true;
		}else{
			return false;
		}
	}
}

配置文件:
exam.properties:

pageSize=10

hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!--数据库连接设置 -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:5722/db_exam?useUnicode=true&amp;characterEncoding=UTF-8</property>
        <property name="connection.username">root</property>
        <property name="connection.password">lz123456</property>

       
        <!-- 方言 -->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

        <!-- 把session绑定到当前线程中 -->
        <property name="current_session_context_class">thread</property>

        <!-- 显示SQL -->
        <property name="show_sql">true</property>

        <!-- 自动表更新 -->
        <property name="hbm2ddl.auto">update</property>
        
        <mapping class="com.ischoolbar.programmer.model.Student"/>
        <mapping class="com.ischoolbar.programmer.model.Question"/>
        <mapping class="com.ischoolbar.programmer.model.Paper"/>
     	<mapping class="com.ischoolbar.programmer.model.Exam"/>
     	<mapping class="com.ischoolbar.programmer.model.Manager"/>

    </session-factory>

</hibernate-configuration>

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

	
	<package name="studentInfo" namespace="/" extends="struts-default">
		
		<action name="student" class="com.ischoolbar.programmer.action.StudentAction">
			<result name="success">/main.jsp</result>
			<result name="error">/login.jsp</result>
			<result name="logout" type="redirect">/login.jsp</result>
			<result name="save" type="redirectAction">student!list</result>
		</action>
		
		<action name="paper" class="com.ischoolbar.programmer.action.PaperAction">
			<result name="success">/main.jsp</result>
			<result name="save" type="redirectAction">paper!paperList</result>
		</action>
		
		<action name="exam" class="com.ischoolbar.programmer.action.ExamAction">
			<result name="success">/main.jsp</result>
		</action>
		
		<action name="question" class="com.ischoolbar.programmer.action.QuestionAction">
			<result name="success">/main.jsp</result>
			<result name="save" type="redirectAction">question!list</result>
		</action>
		
		<action name="manager" class="com.ischoolbar.programmer.action.ManagerAction">
			<result name="success">/main.jsp</result>
			<result name="error">/login2.jsp</result>
			<result name="logout" type="redirect">/login2.jsp</result>
		</action>
		
	</package>
	

     
</struts>

(4)jsp代码:
在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<div>
	<h1>登录成功!</hl>
	</br>
	<h2>欢迎使用!</h2>
</div>
<div>
<h1>考生须知:</h1>
	(1) 考试前30分钟,考生必须进入考场,考试后20分钟,迟到考生不得进入考场。
	</br>
	(2) 考生进入考场后,需要服从工作人员的安排,进入考场后,需要在考试规定的签到表上进行签到。
	</br>
	(3) 进入考场必须携带有效证件。
	</br>
	(4) 入座后不得交头接耳。
	</br>
	(5) 考试开始后,考生可以交卷但是不得大声喧哗,影响他人。
	</br>
	(6) 考生在考试期间,应当自觉遵守考场纪律,如被监考人员发现违反考场纪律的行为,应当主动配合监考人员的检查。
	</br>
	(7) 自觉遵守考场纪律,保持考场安静,如出现无法登录服务器,信息有误,运行故障等异常情况,请立即联系监考人员。
	</br>
</div>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<div align="center">
		<div class="foot">Copyright © 2019-  </div>
</div>
``

`<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<div align="center">
	<div style="background: url('${pageContext.request.contextPath}/image/firsthead.png');height:90px;width:1000px;float:right;" ><font style="float: right;padding: 65px 20px 20px 10px;">欢迎:<strong>${currentUser.name }</strong></font></div>
</div>

<%@ page language=“java” contentType=“text/html; charset=utf-8” pageEncoding=“utf-8”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>

```

在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<div class="data_list">
	<div class="data_info">
		<p>考生成绩列表</p>
	</div>
	<div class="search_content">
		<form action="${pageContext.request.contextPath}/exam!examList" method="post">
			<table align="center">
				<tr>
					<td><label>准考证号:</label></td>
					<td><input type="text" id="s_id" name="s_exam.student.id" value="${s_exam.student.id }"/></td>
					<td>&nbsp;</td>
					<td><label>姓名:</label></td>
					<td><input type="text" id="s_name" name="s_exam.student.name" value="${s_exam.student.name }"/></td>
					<td>&nbsp;</td>
					<td><button class="btn btn-primary" style="margin-bottom: 8px;" type="submit" >查询</button></td>
				</tr>
			</table>
		</form>
	</div>
	<div class="data_content">
		<table class="table table-bordered table-hover">
			 <tr>
				<th>序号</th>
				<th>准考证号</th>
				<th>考生姓名</th>
				<th>试卷名称</th>
				<th>考试日期</th>
				<th>单选题得分</th>
				<th>多选题得分</th>
				<th>总分</th>
			</tr>
			<c:forEach var="exam" items="${examList}" varStatus="status" >
				<tr>
					<td>${status.index+1 }</td>
					<td>${exam.student.id }</td>
					<td>${exam.student.name }</td>
					<td>${exam.paper.paperName }</td>
					<td><fmt:formatDate value="${exam.examDate }" type="date" pattern="yyyy-MM-dd"/></td>
					<td>${exam.singleScore }</td>
					<td>${exam.moreScore }</td>
					<td><font color="red">${exam.score }</font></td>
				</tr>
			</c:forEach>
	  </table>
	</div>
	<div class="pagination pagination-centered">
	 	 <ul>
	    	${pageCode }
	 	 </ul>
	</div>
</div>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<p class="examResult" align="center">
	试卷已提交,您本次考试的成绩为:<font color="red">${exam.score }</font>分!
</p>
		

<%@ page language=“java” contentType=“text/html; charset=utf-8” pageEncoding=“utf-8”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>
<%@ taglib prefix=“fmt” uri=“http://java.sun.com/jsp/jstl/fmt”%>

${currentUser.name } 成绩列表

序号试卷名称考试日期单选题得分多选题得分总分
${status.index+1 }${exam.paper.paperName }${exam.singleScore }${exam.moreScore }${exam.score }
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript">
	var examTime=20*60; 
	var useTime=0,remainTime=examTime; 
	
	// 显示使用时间和剩余时间
	function showCount(){
		if(remainTime==0){
			document.getElementById("myForm").submit();
		}
		useTime+=1;
		remainTime-=1;
		var hourU=Math.floor(useTime/3600);
		var minuteU=Math.floor((useTime-hourU*3600)/60);
		var secondU=Math.floor(useTime-hourU*3600-minuteU*60);
		document.getElementById("useTime").innerHTML=format(hourU)+":"+format(minuteU)+":"+format(secondU);
		
		var hourR=Math.floor(remainTime/3600);
		var minuteR=Math.floor((remainTime-hourR*3600)/60);
		var secondR=Math.floor(remainTime-hourR*3600-minuteR*60);
		document.getElementById("remainTime").innerHTML=format(hourR)+":"+format(minuteR)+":"+format(secondR);
	}
	
	// 格式化日期数字
	function format(timeNumber){
		if(timeNumber==0){
			return "00";
		}else if(timeNumber<10){
			return "0"+timeNumber;
		}else{
			return timeNumber;
		}
	}
	
	window.setInterval("showCount()",1000);
</script>
<div class="data_list">
	<div class="data_info">
		<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;考试时间:<strong>20分钟</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		计时:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font id="useTime" style="font-weight: bold;"></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		剩余时间:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font id="remainTime" style="font-weight: bold;"></font></p>
		<hr/>
		<p class="examTitle">${paper.paperName}&nbsp;&nbsp;考试卷</p>
		<p class="examScoreInfo">(&nbsp;满分120&nbsp;&nbsp;单选题60分&nbsp;&nbsp;多选题60分&nbsp;)</p>
	</div>
	<div class="data_content">
		<strong><big>一,单选题</big></strong>(每题20分,答错不得分)<br/><br/>
		<form id="myForm" action="exam!add" method="post">
		<input type="hidden" name="exam.student.id" value="${currentUser.id }"/>
		<input type="hidden" name="exam.paper.id" value="${paper.id }"/>
		<c:forEach var="s" items="${squestionList }" varStatus="status">
			<strong>[&nbsp;${status.index+1}&nbsp;]&nbsp;${s.subject }</strong><br/><br/>
			<label class="radio">
			  <input type="radio" name="id-r-${s.id }"  value="A">
			  ${s.optionA }
			</label>
			<label class="radio">
			  <input type="radio" name="id-r-${s.id }"  value="B">
			  ${s.optionB }
			</label>
			<label class="radio">
			  <input type="radio" name="id-r-${s.id }"  value="C">
			  ${s.optionC }
			</label>
			<label class="radio">
			  <input type="radio" name="id-r-${s.id }"  value="D">
			  ${s.optionD }
			</label>
			<br/>
		</c:forEach>
		<strong><big>二,多选题</big></strong>(每题30分,答错不得分)<br/><br/>
		<c:forEach var="m" items="${mquestionList }" varStatus="status">
			<strong>[&nbsp;${status.index+1}&nbsp;]&nbsp;${m.subject }</strong><br/><br/>
			<label class="checkbox">
			  <input type="checkbox" name="id-c-${m.id }" value="A">
			  ${m.optionA }
			</label>
			<label class="checkbox">
			  <input type="checkbox" name="id-c-${m.id }" value="B">
			  ${m.optionB }
			</label>
			<label class="checkbox">
			  <input type="checkbox" name="id-c-${m.id }" value="C">
			  ${m.optionC }
			</label>
			<label class="checkbox">
			  <input type="checkbox" name="id-c-${m.id }" value="D">
			  ${m.optionD }
			</label>
			<br/>
		</c:forEach>
		<button class="btn btn-primary" type="submit">交卷</button>
		</form>
	</div>
</div>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript">
	function checkForm(){
		var paperId=$("#paperId").val();
		if(paperId==null||paperId==""){
			alert("请选择考试试卷!");
			return false;
		}
		return true;
	}
</script>
<div class="data_list">
	<div class="data_content">
		<form action="paper!getDetailPaper" method="post" onsubmit="return checkForm()">
			<table width="40%" align="center">
				<tr>
					<td><label><strong>请选择考试试卷:</strong></label></td>
					<td>
						<select id="paperId" name="paperId">
							<option value="">请选择...</option>
							<c:forEach var="paper" items="${paperList }">
								<option value="${paper.id}" >${paper.paperName}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr>
					<td>
						<input type="submit" class="btn  btn-primary" value="确定"/>
					</td> 
					<td>
						<input type="button" class="btn  btn-primary" value="返回" onclick="javascript:history.back() "/>
					</td>
				</tr>
			</table>
		</form> 
	</div>
</div>

在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript">
	function paperDelete(paperId){
		if(confirm("确定要删除这个试卷吗?")){
			$.post("paper!deletePaper",{paperId:paperId},
				function(result){
					var result = eval('('+result+')');
					if(result.error){
						alert(result.error);
					}else{
						alert("删除成功!");
						window.location.href="${pageContext.request.contextPath}/paper!paperList";
					}
				}
			);
		}
	}
</script>
<div class="data_list">
	<div class="data_info">
		<p>试卷管理</p>
	</div>
	<div class="search_content">
		<button class="btn-mini btn-primary" style="float: right;margin-bottom: 5px;" type="button" onclick="javascript:window.location='paper!preSave'">添加试卷</button>
	</div>
	<div class="data_content">
		<table class="table table-bordered table-hover">
			 <tr>
				<th>序号</th>
				<th>试卷名称</th>
				<th>添加日期</th>
				<th>操作</th>
			</tr>
			<c:forEach var="paper" items="${paperList}" varStatus="status" >
				<tr>
					<td>${status.index+1 }</td>
					<td>${paper.paperName }</td>
					<td><fmt:formatDate value="${paper.joinDate }" type="date" pattern="yyyy-MM-dd"/></td>
					<td><button class="btn-mini btn-info" type="button" onclick="javascript:window.location='paper!preSave?paperId=${paper.id}'">修改</button>&nbsp;&nbsp;<button class="btn-mini btn-danger" type="button" onclick="paperDelete(${paper.id })">删除</button></td>
				</tr>
			</c:forEach>
	  </table>
	</div>
</div>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript">
	function checkForm(){
		var paperName=$("#paperName").val();
		if(paperName==null||paperName==""){
			$("#error").html("试卷名称不能为空!");
			return false;
		}
		return true;
	}
</script>
<div class="data_list">
	<div class="data_info">
		<p>${title }</p>
	</div>
	<div class="data_content" >
		<form action="paper!savePaper" method="post" onsubmit="return checkForm()">
		<table width="40%" align="center">
			<tr>
				<td><label>试卷名称:</label></td>
				<td><input type="text" id="paperName" name="paper.paperName" value="${paper.paperName }"/></td>
			</tr>
			<tr>
				<td>
					<input type="hidden" id="joinDate" name="paper.joinDate" value="${paper.joinDate }"/>
					<input type="hidden" id="id" name="paperId" value="${paper.id }"/>
					<input type="submit" class="btn btn-primary" value="保存"/>
				</td>
				<td colspan="4">
		   		   <button class="btn btn-primary" type="button" onclick="javascript:history.back()">返回</button>&nbsp;&nbsp;<font id="error" color="red">${error }</font>
				</td>
			</tr>
		</table>
		</form>
	</div>
</div>

在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript">
	function studentDelete(questionId){
		if(confirm("确定要删除这条记录吗?")){
			$.post("question!delete",{questionId:questionId},
				function(result){
					var result = eval('('+result+')');
					if(result.error){
						alert(result.error);
					}else{
						alert("删除成功!");
						window.location.href="${pageContext.request.contextPath}/question!list";
					}
				}
			);
		}
	}
</script>
<div class="data_list">
	<div class="data_info">
		<p>试题信息管理</p>
	</div>
	<div class="search_content">
		<form action="${pageContext.request.contextPath}/question!list" method="post">
			<table align="center">
				<tr>
					<td><label>考试题目:</label></td>
					<td><input type="text" id="s_subject" name="s_question.subject" value="${s_question.subject }"/></td>
					<td><button class="btn btn-primary" style="margin-bottom: 8px;" type="submit" >查询</button></td>
				</tr>
			</table>
		</form>
		<button class="btn-mini btn-primary" style="float: right;margin-bottom: 5px;" type="button" onclick="javascript:window.location='question!preSave'">添加考生题目</button>
	</div>
	<div class="data_content">
		<table class="table table-bordered table-hover">
			 <tr>
				<th>序号</th>
				<th>考试题目</th>
				<th>加入时间</th>
				<th>题目类型</th>
				<th>所属试卷</th>
				<th>操作</th>
			</tr>
			<c:forEach var="question" items="${questionList}" varStatus="status" >
				<tr>
					<td>${status.index+1 }</td>
					<td>${question.subject }</td>
					<td><fmt:formatDate value="${question.joinTime }" type="date" pattern="yyyy-MM-dd"/></td>
					<c:choose>
						<c:when test="${question.type==1 }">
							<td>单选题</td>
						</c:when>
						<c:otherwise>
							<td>多选题</td>
						</c:otherwise>
					</c:choose>
					<td>${question.paper.paperName }</td>
					<td><button class="btn-mini btn-info" type="button" onclick="javascript:window.location='question!getQuestionById?questionId=${question.id}'">查看试题</button>&nbsp;&nbsp;<button class="btn-mini btn-info" type="button" onclick="javascript:window.location='question!preSave?questionId=${question.id}'">修改</button>&nbsp;&nbsp;<button class="btn-mini btn-danger" type="button" onclick="studentDelete(${question.id })">删除</button></td>
				</tr>
			</c:forEach>
	  </table>
	</div>
	<div class="pagination pagination-centered">
	 	 <ul>
	    	${pageCode }
	 	 </ul>
	</div>
</div>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript">
	function checkForm(){
		var subject=$("#subject").val();
		var type=$("#type").val();
		var paperName=$("#paperName").val();
		var joinTime=$("#joinTime").val();
		var optionA=$("#optionA").val();
		var optionB=$("#optionB").val();
		var optionC=$("#optionC").val();
		var optionD=$("#optionD").val();
		var answer=$("#answer").val();
		if(subject==null||subject==""){
			$("#error").html("考试题目不能为空!");
			return false;
		}
		if(type==null||type==""){
			$("#error").html("请选择题目类型!");
			return false;
		}
		if(paperName==null||paperName==""){
			$("#error").html("请选择试卷!");
			return false;
		}
		if(joinTime==null||joinTime==""){
			$("#error").html("加入时间不能为空!");
			return false;
		}
		if(optionA==null||optionA==""){
			$("#error").html("选项一不能为空!");
			return false;
		}
		if(optionB==null||optionB==""){
			$("#error").html("选项二不能为空!");
			return false;
		}
		if(optionC==null||optionC==""){
			$("#error").html("选项三不能为空!");
			return false;
		}
		if(optionD==null||optionD==""){
			$("#error").html("选项四不能为空!");
			return false;
		}
		if(answer==null||answer==""){
			$("#error").html("答案不能为空!");
			return false;
		}
		return true;
	}
</script>
<div class="data_list">
	<div class="data_info">
		<p>${title }</p>
	</div>
	<div class="data_content" >
		<form action="question!saveQuestion" method="post" onsubmit="return checkForm()">
		<table width="90%" align="center">
			<tr>
				<td><label>考试题目:</label></td>
				<td><input type="text" id="subject" name="question.subject" value="${question.subject }" class="input-xxlarge"/></td>
			</tr>
			<tr>
				<td><label>题目类型:</label></td>
				<td>
					<select id="type" name="question.type">
						<option value="">请选择题目类型...</option>
						<option value="1" ${question.type==1?'selected':'' }>单选题</option>
						<option value="2" ${question.type==2?'selected':'' }>多选题</option>
					 </select>
				</td>
			</tr>
			<tr>
				<td><label>所属试卷:</label></td>
				<td>
					<select id="paperName" name="question.paper.id">
						<option value="">请选择试卷...</option>
						<c:forEach var="paper" items="${paperList }">
							<option value="${paper.id }" ${paper.id==question.paper.id?'selected':'' }>${paper.paperName }</option>
						</c:forEach>
					 </select>
				</td>
			</tr>
			<tr>
				<td><label>加入时间:</label></td>
				<td><input type="text" id="joinTime" name="question.joinTime" class="Wdate" onClick="WdatePicker()" value="<fmt:formatDate value="${question.joinTime }" type="date" pattern="yyyy-MM-dd"/>"/></td>
			</tr>
			<tr>
				<td><label>选项一:</label></td>
				<td><input type="text" id="optionA" name="question.optionA" value="${question.optionA }"/></td>
			</tr>
			<tr>
				<td><label>选项二:</label></td>
				<td><input type="text" id="optionB" name="question.optionB" value="${question.optionB }"/></td>
			</tr>
			<tr>
				<td><label>选项三:</label></td>
				<td><input type="text" id="optionC" name="question.optionC" value="${question.optionC }"/></td>
			</tr>
			<tr>
				<td><label>选项四:</label></td>
				<td><input type="text" id="optionD" name="question.optionD" value="${question.optionD }"/></td>
			</tr>
			<tr>
				<td><label>题目答案:</label></td>
				<td><input type="text" id="answer" name="question.answer" value="${question.answer }"/>&nbsp;&nbsp;(多选题答案用逗号隔开,如"A,D")</td>
			</tr>
			<tr>
				<td>
					<input type="hidden" id="questionId" name="questionId" value="${question.id }"/><input type="submit" class="btn btn-primary" value="保存"/>
				</td>
				<td>
					
		   		   <button class="btn btn-primary" type="button" onclick="javascript:history.back()">返回</button>&nbsp;&nbsp;<font id="error" color="red">${error }</font>
				</td>
			</tr>
		</table>
		</form>
	</div>
</div>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<div class="data_list">
	<div class="data_info">
		<p>查看试题</p>
	</div>
	<div class="data_content" >
		<table width="90%" align="center">
			<tr>
				<td><label>考试题目:</label></td>
				<td><input type="text" id="subject" value="${question.subject }" readonly="readonly" class="input-xxlarge"/></td>
			</tr>
			<tr>
				<td><label>题目类型:</label></td>
				<td>
					<c:choose>
						<c:when test="${question.type==1 }">
							<input type="text" id="type"  value="单选题" readonly="readonly"/>
						</c:when>
						<c:otherwise>
							<input type="text" id="type"  value="多选题" readonly="readonly"/>
						</c:otherwise>
					</c:choose>
				</td>
			</tr>
			<tr>
				<td><label>所属试卷:</label></td>
				<td><input type="text" id="paperName" readonly="readonly" value="${question.paper.paperName }"/></td>
			</tr>
			<tr>
				<td><label>加入时间:</label></td>
				<td><input type="text" id="joinTime" readonly="readonly" value="<fmt:formatDate value="${question.joinTime }" type="date" pattern="yyyy-MM-dd"/>"/></td>
			</tr>
			<tr>
				<td><label>选项一:</label></td>
				<td><input type="text" id="optionA" readonly="readonly" value="${question.optionA }"/></td>
			</tr>
			<tr>
				<td><label>选项二:</label></td>
				<td><input type="text" id="optionB" readonly="readonly" value="${question.optionB }"/></td>
			</tr>
			<tr>
				<td><label>选项三:</label></td>
				<td><input type="text" id="optionC" readonly="readonly" value="${question.optionC }"/></td>
			</tr>
			<tr>
				<td><label>选项四:</label></td>
				<td><input type="text" id="optionD" readonly="readonly" value="${question.optionD }"/></td>
			</tr>
			<tr>
				<td><label>题目答案:</label></td>
				<td><input type="text" id="answer" readonly="readonly" value="${question.answer }"/></td>
			</tr>
			<tr>
				<td colspan="2">
		   		   <button class="btn btn-primary" type="button" onclick="javascript:history.back()">返回</button>
				</td>
			</tr>
		</table>
	</div>
</div>

在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript">
	function studentDelete(studentId){
		if(confirm("确定要删除这条记录吗?")){
			$.post("student!deleteStudent",{id:studentId},
				function(result){
					var result = eval('('+result+')');
					if(result.error){
						alert(result.error);
					}else{
						alert("删除成功!");
						window.location.href="${pageContext.request.contextPath}/student!list";
					}
				}
			);
		}
	}
</script>
<div class="data_list">
	<div class="data_info">
		<p>考生信息管理</p>
	</div>
	<div class="search_content">
		<form action="${pageContext.request.contextPath}/student!list" method="post">
			<table align="center">
				<tr>
					<td><label>准考证号:</label></td>
					<td><input type="text" id="s_id" name="s_student.id" value="${s_student.id }"/></td>
					<td>&nbsp;</td>
					<td><label>姓名:</label></td>
					<td><input type="text" id="s_name" name="s_student.name" value="${s_student.name }"/></td>
					<td>&nbsp;</td>
					<td><button class="btn btn-primary" style="margin-bottom: 8px;" type="submit" >查询</button></td>
				</tr>
			</table>
		</form>
		<button class="btn-mini btn-primary" style="float: right;margin-bottom: 5px;" type="button" onclick="javascript:window.location='student!preSave'">添加考生信息</button>
	</div>
	<div class="data_content">
		<table class="table table-bordered table-hover">
			 <tr>
				<th>序号</th>
				<th>准考证号</th>
				<th>姓名</th>
				<th>性别</th>
				<th>身份证</th>
				<th>密码</th>
				<th>专业</th>
				<th>操作</th>
			</tr>
			<c:forEach var="student" items="${studentList}" varStatus="status" >
				<tr>
					<td>${status.index+1 }</td>
					<td>${student.id }</td>
					<td>${student.name }</td>
					<td>${student.sex }</td>
					<td>${student.cardNo }</td>
					<td>${student.password }</td>
					<td>${student.prefession }</td>
					<td><button class="btn-mini btn-info" type="button" onclick="javascript:window.location='student!preSave?id=${student.id}'">修改</button>&nbsp;&nbsp;<button class="btn-mini btn-danger" type="button" onclick="studentDelete('${student.id }')">删除</button></td>
				</tr>
			</c:forEach>
	  </table>
	</div>
	<div class="pagination pagination-centered">
	 	 <ul>
	    	${pageCode }
	 	 </ul>
	</div>
</div>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript">
	function checkForm(){
		var name=$("#name").val();
		var sex=$("#sex").val();
		var cardNo=$("#cardNo").val();
		var prefession=$("#prefession").val();
		var password=$("#password").val();
		if(name==null||name==""){
			$("#error").html("姓名不能为空!");
			return false;
		}
		if(sex==null||sex==""){
			$("#error").html("请选择性别!");
			return false;
		}
		if(cardNo==null||cardNo==""){
			$("#error").html("身份证不能为空!");
			return false;
		}
		if(prefession==null||prefession==""){
			$("#error").html("专业不能为空!");
			return false;
		}
		if(password==null||password==""){
			$("#error").html("密码不能为空!");
			return false;
		}
		return true;
	}
</script>
<div class="data_list">
	<div class="data_info">
		<p>${title }</p>
	</div>
	<div class="data_content" >
		<form action="student!saveStudent" method="post" onsubmit="return checkForm()">
		<table width="80%" align="center">
			<tr>
				<td><label>姓名:</label></td>
				<td><input type="text" id="name" name="student.name" value="${student.name }"/></td>
				<td>&nbsp;</td>
				<td><label>性别:</label></td>
				<td>
					<select id="sex" name="student.sex">
						<option value="">请选择性别...</option>
						<option value="男" ${student.sex=='男'?'selected':'' }>男</option>
						<option value="女" ${student.sex=='女'?'selected':'' }>女</option>
					 </select>
				</td>
			</tr>
			<tr>
				<td><label>身份证:</label></td>
				<td colspan="4">
						<input type="text" id="cardNo" name="student.cardNo" value="${student.cardNo }" class="input-xlarge"/>
				</td>
			</tr>
			<tr>
				<td><label>专业:</label></td>
				<td>
					<input type="text" id="prefession" name="student.prefession" value="${student.prefession }"/>
				</td>
				<td>&nbsp;</td>
				<td><label>密码:</label></td>
				<td>
					<input type="text" id="password" name="student.password" value="${student.password }"/>
				</td>
			</tr>
			<tr>
				<td>
					<input type="hidden" id="id" name="student.id" value="${student.id }"/><input type="submit" class="btn btn-primary" value="保存"/>
				</td>
				<td colspan="4">
		   		   <button class="btn btn-primary" type="button" onclick="javascript:history.back()">返回</button>&nbsp;&nbsp;<font id="error" color="red">${error }</font>
				</td>
			</tr>
		</table>
		</form>
	</div>
</div>

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript">
	function checkForm(){
		var oldPassword=$("#oldPassword").val();
		var newPassword1=$("#newPassword1").val();
		var newPassword2=$("#newPassword2").val();
		if(oldPassword==null||oldPassword==""){
			alert("请输入原密码!");
			return false;
		}
		if(oldPassword!='${currentUser.password}'){
			alert("原密码错误,请重新输入");
			return false;
		}
		if(newPassword1==null||newPassword1==""){
			alert("请输入新密码!");
			return false;
		}
		if(newPassword2==null||newPassword2==""){
			alert("请输入确认新密码!");
			return false;
		}
		if(newPassword1!=newPassword2){
			alert("确认新密码填写错误,请重新输入!");
			return false;
		}
		return true;
	}
</script>
<div class="data_list">
	<div class="data_info">
		<p>修改个人密码</p>
	</div>
	<div class="data_content">
		<form action="student!updatePassword" method="post" onsubmit="return checkForm()">
			<table width="40%" align="center">
				<tr>
					<td><label>用户名:</td>
					<td>
						<input type="text" value="${currentUser.id }" name="student.id" readonly="readonly"/>
					</td>
				</tr>
				<tr>
					<td><label>原密码:</td>
					<td>
						<input type="password" id="oldPassword" />
					</td>
				</tr>
				<tr>
					<td><label>新密码:</td>
					<td>
						<input type="password" id="newPassword1"  name="student.password"/>
					</td>
				</tr>
				<tr>
					<td><label>确认新密码:</td>
					<td>
						<input type="password" id="newPassword2"  />
					</td>
				</tr>
				<tr>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="2">
						<input type="submit" class="btn  btn-primary" value="修改密码"/>
					</td> 
					
				</tr>
			</table>
		</form> 
	</div>
</div>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<div style="padding-top: 30px;padding-bottom: 30px;">
	<p align="center" style="font-size: 30px;">密码修改成功,下一次登录生效!</p>
</div>

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Exam</display-name>
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
        <filter-name>StrutsPrepareAndExecuteFilter</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
	   <filter-name>StrutsPrepareAndExecuteFilter</filter-name>
	   <url-pattern>/*</url-pattern>
  </filter-mapping>
  
</web-app>

在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>考生登录</title>
<link href="${pageContext.request.contextPath}/style/studentInfo.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/bootstrap/js/jQuery.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"></script>

<script type="text/javascript">
	function checkForm(){
		var id=document.getElementById("id").value;
		var password=document.getElementById("password").value;
		if(id==null||id==""){
			alert("准考证号不能为空!");
			return false;
		}
		if(password==null||password==""){
			alert("登录密码不能为空!");
			return false;
		}
		return true;
	}
	
	function resetValue(){
		document.getElementById("id").value="";
		document.getElementById("password").value="";
	}
</script>
</head>
<body >
<div align="center" style="padding-top: 20px;" >
		<form action="student!login" method="post" onsubmit="return checkForm()">
		<table  width="1004" height="584" background="image/user.jpg" >
			<tr height="200">
				<td colspan="4"></td>
			</tr>
			<tr height="10">
				<td width="68%"></td>
				<td width="10%"><label>准考证号:</label></td>
				<td><input type="text" id="id" name="student.id" value="${student.id }" placeholder="请输入准考证号"/></td>
				<td width="30%"></td>
			</tr>
			<tr height="10">
				<td width="40%"></td>
				<td width="10%"><label>登录密码:</label></td>
				<td><input type="password" id="password" name="student.password" value="${student.password }" placeholder="请输入密码"/></td>
				<td width="30%"></td>
			</tr>
			<tr height="10">
				<td width="40%"></td>
				<td width="10%"><button class="btn btn-primary" type="submit">登录</button></td>
				<td>
					<button class="btn btn-primary" type="button"  onclick="resetValue()">重置</button>
					<a class="btn btn-primary" style="margin-left:30px;" href="login2.jsp">登录后台</a>
				</td>
				<td width="20%"></td>
			</tr>
			<tr >
				<td></td>
				<td></td>
				<td></td>
				<td style=""></td>
			</tr>
		</table>
		</form>
	</div>
</body>
</html>
<script type="text/javascript">
	if('${error}'!=''){
		alert('${error}');
	}
</script>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>管理员登录考试系统</title>
<link href="${pageContext.request.contextPath}/style/studentInfo.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/bootstrap/js/jQuery.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"></script>

<script type="text/javascript">
	function checkForm(){
		var userName=document.getElementById("userName").value;
		var password=document.getElementById("password").value;
		if(userName==null||userName==""){
			alert("用户名不能为空!");
			return false;
		}
		if(password==null||password==""){
			alert("密码不能为空!");
			return false;
		}
		return true;
	}
	
	function resetValue(){
		document.getElementById("userName").value="";
		document.getElementById("password").value="";
	}
</script>
</head>
<body >
<div align="center" style="padding-top: 20px;" >
		<form action="manager!login" method="post" onsubmit="return checkForm()">
		<table  width="1004" height="584" background="image/admain.jpg" >
			<tr height="200">
				<td colspan="4"></td>
			</tr>
			<tr height="10">
				<td width="68%"></td>
				<td width="10%"><label>用户名:</label></td>
				<td><input type="text" id="userName" name="manager.userName" value="${manager.userName }" placeholder="请输入管理员用户名"/></td>
				<td width="30%"></td>
			</tr>
			<tr height="10">
				<td width="40%"></td>
				<td width="10%"><label>密码:</label></td>
				<td><input type="password" id="password" name="manager.password" value="${manager.password }" placeholder="请输入管理员密码"/></td>
				<td width="30%"></td>
			</tr>
			<tr height="10">
				<td width="40%"></td>
				<td width="10%"><button class="btn btn-primary" type="submit">登录</button></td>
				<td>
					<button class="btn btn-primary" type="button"  onclick="resetValue()">重置</button>
					<a class="btn btn-primary" style="margin-left:30px;" href="login.jsp">考生登录</a>
				</td>
				<td width="30%"></td>
			</tr>
			<tr>
				<td></td>
			</tr>
		</table>
		</form>
	</div>
</body>
</html>
<script type="text/javascript">
	if('${error}'!=''){
		alert('${error}');
	}
</script>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>在线考试系统主界面</title>
<link href="${pageContext.request.contextPath}/style/exam.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/bootstrap/js/jQuery.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"></script>

<script src="${pageContext.request.contextPath}/js/My97DatePicker/WdatePicker.js"></script>
</head>
<%
	String mainPage=(String)request.getAttribute("mainPage");
	if(mainPage==null || mainPage.equals("")){
		mainPage="common/default.jsp";
	}
%>
<body>
<table width="1000px;" align="center">
	<tr>
		<td>
			<jsp:include page="common/head.jsp"/>
		</td>
	</tr>
	<tr>
		<td>
			<jsp:include page="common/menu.jsp"/>
		</td>
	</tr>
	<tr>
		<td>
			<jsp:include page="<%=mainPage %>"/>
		</td>
	</tr>
	<tr>
		<td>
			<jsp:include page="common/foot.jsp"/>
		</td>
	</tr>
</table>
</body>
</html>

还有一些必要的开发包:
在这里插入图片描述
在这里插入图片描述
这个很重要:
在这里插入图片描述

.foot{
	text-align: center;
	margin-top:18px;
	margin-bottom: 18px;
}

.defaultPage{
	text-align:center;
	margin-top: 120px;
	font-size: 25px;
	color: lavender;
	height: 300px;
}

.examMenu{
	margin-top: 15px;
}

.data_list{
	margin-top: 10px;
}

.data_list .data_content{
	margin-top: 15px;
}

.data_list .data_info .examTitle{
	font-size: 30px;
	font-weight: bold;
	text-align: center;
	padding-top: 30px;
}

.data_list .data_info .examScoreInfo{
	padding:10px;
	font-weight: bold;
	text-align: right;
}

.examResult{
	font-size: 20px;
	padding: 120px;
}

.data_list .data_info p{
	text-align: center;
	font-size: 20px;
	font-weight: bold;
	padding-bottom: 10px;
}

.data_list .search_content form{
	text-align:center;
	margin: 0px;
}

(5)实现效果:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
学生端和考生端差不多就不截图了。

  • 8
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值