基于javaweb+mysql的ssh课程资源教学在线考试平台(java+ssh+mysql+jsp+tomcat)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSH课程资源教学在线考试平台(java+ssh+mysql+jsp+tomcat)
一、项目简述
功能包括: 管理员可以增删改查教材、教材商、入库教材、用户(用 户包括学生和教师)可以对教材商、教材进行。xcel的导入 导出操作。教师可以领取入库的教材,可以退还教材。学 生只能在对应的教师那里领取教材,并且可以退还教材、 查询自己已经领取的教材。并且对已领教材付款等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Struts+Spring+Hibernate + html+ css + JavaScript + JQuery + Ajax等等。
alert("选项C不能为空!!");
f.option3.focus();
return false;
}
if(f.option4.value==""){
alert("选项D不能为空!!");
f.option4.focus();
return false;
}
}
if(f.answer.value==""){
alert("答案不能为空!!");
f.answer.focus();
return false;
}
if(course.value==""){
alert("请选择所属课程!");
return false;
}
if(f.difficulty.value==""){
alert("请选择试题难度!");
return false;
}
return true;
}
function init(){
var type = "${requestScope.question.type}";
var typename = document.getElementById("typename");
switch(type){
case "single":
typename.innerHTML="单选题";
break;
case "multiple":
typename.innerHTML="多选题";
break;
case "judgment":
typename.innerHTML="判断题";
break;
default:
typename.innerHTML="解答题";
break;
}
}
</script>
</head>
<body onload="init();">
<form action="questionAction_update" method="post" role="form" onSubmit="return checkForm(this)">
<div style="width:1000;margin:20">
chat.setTeacher(teacher);
chat.setDirection(2);
chat.setTime(new Date());
chatService.saveChat(chat);
if(student.getStatus()==1){
SystemMail.sendMail(student.getEmail(), teacher.getName(), student.getName(), 2);
}
List<Student> students = studentService.findStudentInChat(teacher.getTid());
List<Chat> chats = chatService.findChatByTS(teacher.getTid(), student.getSid());
ActionContext.getContext().put("student", student);
ActionContext.getContext().put("students", students);
ActionContext.getContext().put("chats", chats);
return "beforChat";
}
}
/**
* 使用hibernate.cfg.xml
*/
//public class UserDaoImpl implements UserDao {
// // 提供hibernate模板
// private HibernateTemplate hibernateTemplate;
// public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
// this.hibernateTemplate = hibernateTemplate;
// }
// public User findById(Integer id) {
// return this.hibernateTemplate.get(User.class, id);
// }
// public List<User> findAll() {
// return this.hibernateTemplate.find("from User");
// }
// public void save(User user) {
// this.hibernateTemplate.save(user);
// }
// public void update(User user) {
// this.hibernateTemplate.update(user);
// }
ActionContext.getContext().put("themes",themes);
return "selectAllForA";
}
public String adminDelete() {
themeService.deleteTheme(theme);
return this.selectAllForA();
}
public String update(){
this.themeService.updateTheme(theme);
return "success";
}
public String delete(){
themeService.deleteTheme(theme);
List<Theme> themes = themeService.findAllTheme();
ActionContext.getContext().put("themes", themes);
return "selectAll";
}
public String add(){
theme.setReplies(0);
theme.setSendtime(new Date());
themeService.saveTheme(theme);
List<Theme> themes = themeService.findAllTheme();
ActionContext.getContext().put("themes",themes);
return "selectAll";
}
public String showTheme(){
Theme theme = themeService.findThemeById(this.theme.getThid());
List<Reply> replys = replyService.findReplyByThid(this.theme.getThid());
ActionContext.getContext().put("theme1", theme);
ActionContext.getContext().put("replys", replys);
return "showTheme";
}
}
}
if(course.value==""){
alert("请选择所属课程!");
return false;
}
if(f.difficulty.value==""){
alert("请选择试题难度!");
return false;
}
return true;
}
function init(){
var type = "${requestScope.type}";
var typename = document.getElementById("typename");
switch(type){
case "single":
typename.innerHTML="单选题";
break;
case "multiple":
typename.innerHTML="多选题";
break;
case "judgment":
typename.innerHTML="判断题";
break;
default:
typename.innerHTML="解答题";
break;
}
}
</script>
</head>
<body onload="init();">
<form action="questionAction_add" method="post" role="form" onSubmit="return checkForm(this)">
<div style="width:1000;margin:20">
<table class="table table-bordered table-hover">
<thead>
<tr align="center">
<td colspan="6" class="success"><h3>添加试题信息</h3></td>
</tr>
</thead>
<tbody>
<tr align="center">
<td class="active">试题描述</td>
<td colspan="5"><input type="text" name="description" class="form-control"></td>
</tr>
<tr class="active" align="center">
<td width=100>题型</td>
<td id="typename" align="center" width=100>
</td>
<td width=100>所属课程</td>
public class ExamAction extends ActionSupport implements ModelDriven<Exam>{
private static final long serialVersionUID=1L;
private Exam exam = new Exam();
private List<Integer> scores_m = new ArrayList<Integer>();
public List<Integer> getScores_m() {
return scores_m;
}
public void setScores_m(List<Integer> scores_m) {
this.scores_m = scores_m;
}
Paper paper = new Paper();
Student student = new Student();
public Exam getModel() {
Exam exam = this.exam;
exam.setPaper(paper);
exam.setStudent(student);
return exam;
}
// ***********用于导出excel*********
private String filename;
private String contentType;
public String getFilename() throws IOException{
return encodeDownloadFilename(filename,ServletActionContext.getRequest().getHeader("User-Agent"));
}
public void setFilename(String filename) throws UnsupportedEncodingException{
filename = new String(filename.getBytes("iso-8859-1"),"utf-8");
this.filename = filename;
}
}
// **********上传文件*******************
public String upload() throws Exception {
InputStream is = new FileInputStream(file);
String uploadPath = ServletActionContext.getServletContext().getRealPath("/homeworks");
File toFile = new File(uploadPath, this.getFileFileName());
OutputStream os = new FileOutputStream(toFile);
byte[] buffer = new byte[1024];
int length = 0;
while (-1 != (length = is.read(buffer, 0, buffer.length))) {
os.write(buffer);
}
is.close();
os.close();
homework.setName(fileFileName);
homeworkService.saveHomework(homework);
return "upload";
}
// **********下载文件*******************
public InputStream getDownloadFile() {
String filepath = "/homeworks/" + filename;
return ServletActionContext.getServletContext().getResourceAsStream(filepath);
}
public String encodeDownloadFilename(String name, String agent) throws IOException {
if (agent.contains("Firefox")) {
name = "=?UTF-8?B?" + new BASE64Encoder().encode(name.getBytes("utf-8")) + "?=";
} else {
name = URLEncoder.encode(name, "utf-8");
}
return name;
}
// *****************************
public String selectAll() {
List<Homework> homeworks = homeworkService.findAllHomework();
ActionContext.getContext().put("homeworks", homeworks);
return "selectAll";
}
public String beforeUpdate() {
Homework homework = homeworkService.findHomeworkById(this.homework.getHid());
ActionContext.getContext().put("homework", homework);
return "logoff";
}
}
/**
* 使用hibernate.cfg.xml
*/
//public class UserDaoImpl implements UserDao {
// // 提供hibernate模板
// private HibernateTemplate hibernateTemplate;
// public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
// this.hibernateTemplate = hibernateTemplate;
// }
// public User findById(Integer id) {
// return this.hibernateTemplate.get(User.class, id);
// }
// public List<User> findAll() {
// return this.hibernateTemplate.find("from User");
// }
// public void save(User user) {
// this.hibernateTemplate.save(user);
// }
// public void update(User user) {
// this.hibernateTemplate.update(user);
// }
// public void delete(User user) {
// this.hibernateTemplate.delete(user);
// }
//}
/**
* 不使用hibernate.cfg.xml
*/
// //继承 HibernateDaoSupport自动生成模板, 必须提供SessionFactory
// public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
// public User findById(Integer id) {
// return this.getHibernateTemplate().get(User.class, id);
// }
public class StudentDaoImpl implements StudentDao {
// 提供hibernate模板
private HibernateTemplate hibernateTemplate;
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
public Student findById(String sid) {
return this.hibernateTemplate.get(Student.class, sid);
}
public List<Student> findAll() {
return this.hibernateTemplate.find("from Student");
}
public void save(Student student) {
this.hibernateTemplate.save(student);
}
public void update(Student student) {
this.hibernateTemplate.update(student);
}
public void delete(Student student) {
this.hibernateTemplate.delete(student);
}
public List<Student> findInChat(String tid){
Configuration config=new Configuration().configure();
SessionFactory sessionFactory=config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction t = session.beginTransaction();
Query query=session.createSQLQuery("select * from student s where exists(select * from chat c where s.sid=c.sid and c.tid=?)").addEntity(Student.class);
query.setString(0, tid);
List<Student> students=query.list();
t.commit();
session.close();
sessionFactory.close();
return students;
}
public List<Student> getFromExcel(String file){
List<Student> students = new ArrayList<Student>();
try{
Workbook wb = Workbook.getWorkbook(new File(file));
t.commit();
session.close();
sessionFactory.close();
return questions;
}
}
public class ResourceAction extends ActionSupport implements ModelDriven<Resource>{
private static final long serialVersionUID=1L;
private Resource resource = new Resource();
private Teacher teacher = new Teacher();
public Resource getModel() {
Resource resource = this.resource;
resource.setTeacher(teacher);
return resource;
}
// **********用于上传文件*******************
private File file;
private String fileFileName;
private String fileContentType;
public File getFile() {
return file;
}
name="=?UTF-8?B?"+new BASE64Encoder().encode(name.getBytes("utf-8"))+"?=";
}
else{
name=URLEncoder.encode(name,"utf-8");
}
return name;
}
// *****************************
public String selectAll() {
List<Resource> resources = resourceService.findAllResource();
ActionContext.getContext().put("resources",resources);
return "selectAll";
}
public String beforeUpdate(){
Resource resource = resourceService.findResourceById(this.resource.getRid());
ActionContext.getContext().put("resource", resource);
return "beforeUpdate";
}
public String update(){
this.resourceService.updateResource(resource);
return "success";
}
public String delete(){
resourceService.deleteResource(resource);
List<Resource> resources = resourceService.findAllResource();
ActionContext.getContext().put("resources", resources);
return "selectAll";
}
public String add(){
resourceService.saveResource(resource);
return "success";
}
}
}
return students;
}
public void saveSome(List<Student> students) {
System.out.println("cols:"+students.size());
for(int i=0;i<students.size();i++){
this.hibernateTemplate.save(students.get(i));
}
}
}
@Repository
public class QuestionDaoImpl implements QuestionDao {
private HibernateTemplate hibernateTemplate;
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
public Question findById(Integer qid) {
return this.hibernateTemplate.get(Question.class, qid);
}
public List<Question> findAll() {
return this.hibernateTemplate.find("from Question");
}
public void save(Question question) {
this.hibernateTemplate.save(question);
}
public void update(Question question) {
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
public Exam findById(Integer cid) {
return this.hibernateTemplate.get(Exam.class, cid);
}
public List<Exam> findAll() {
return this.hibernateTemplate.find("from Exam where status=3");
}
public void save(Exam exam) {
this.hibernateTemplate.save(exam);
}
public void update(Exam exam) {
this.hibernateTemplate.update(exam);
}
public void delete(Exam exam) {
this.hibernateTemplate.delete(exam);
}
public List<Exam> findBySid(String sid) {
return this.hibernateTemplate.find("from Exam where student.sid=? and status=3",sid);
}
public List<Exam> findByPid(Integer pid) {
return this.hibernateTemplate.find("from Exam where paper.pid=? and status=3",pid);
}
public Exam findBySP(String sid,Integer pid) {
Configuration config=new Configuration().configure();
SessionFactory sessionFactory=config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction t = session.beginTransaction();
Query query=session.createQuery("from Exam where student.sid=? and paper.pid=?");
query.setString(0, sid);
query.setInteger(1, pid);
List<Exam> exams=query.list();
t.commit();
session.close();
sessionFactory.close();
return exams.get(0);
}
public List<Exam> findUntreated() {
return this.hibernateTemplate.find("from Exam where status=2");
<table class="table table-bordered table-hover">
<thead>
<tr align="center">
<td colspan="6" class="success"><h3>添加试题信息</h3></td>
</tr>
</thead>
<tbody>
<tr align="center">
<td class="active">试题描述</td>
<td colspan="5"><input type="text" name="description" class="form-control"></td>
</tr>
<tr class="active" align="center">
<td width=100>题型</td>
<td id="typename" align="center" width=100>
</td>
<td width=100>所属课程</td>
<td width=200>
<select name="course.cid" id="course" class="form-control">
<s:iterator value="#request.courses" var="course">
<option value="${course.cid}">${course.name}
</s:iterator>
</select>
</td>
<td width=100>难度等级</td>
<td width=200>
<select name="difficulty" class="form-control">
<option value="1"> 简 单
<option value="2"> 中 等
<option value="3"> 困 难
</select>
</td>
</tr>
<s:if test="#type=='single'||#type=='multiple'">
<tr align="center">
<td class="active">选项A</td>
<td colspan="5"><input type="text" name="option1" class="form-control"></td>
</tr>
<tr align="center">
<td class="active">选项B</td>
<td colspan="5"><input type="text" name="option2" class="form-control"></td>
// return this.getHibernateTemplate().find("from User");
// }
// public void save(User user) {
// this.getHibernateTemplate().save(user);
// }
// public void update(User user) {
// this.getHibernateTemplate().update(user);
// }
// public void delete(User user) {
// this.getHibernateTemplate().delete(user);
// }
// }
/**
* 使用注解方式
*/
@Repository
public class StudentDaoImpl implements StudentDao {
// 提供hibernate模板
private HibernateTemplate hibernateTemplate;
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
public Student findById(String sid) {
return this.hibernateTemplate.get(Student.class, sid);
}
public List<Student> findAll() {
return this.hibernateTemplate.find("from Student");
}
public void save(Student student) {
// this.hibernateTemplate = hibernateTemplate;
// }
// public User findById(Integer id) {
// return this.hibernateTemplate.get(User.class, id);
// }
// public List<User> findAll() {
// return this.hibernateTemplate.find("from User");
// }
// public void save(User user) {
// this.hibernateTemplate.save(user);
// }
// public void update(User user) {
// this.hibernateTemplate.update(user);
// }
// public void delete(User user) {
// this.hibernateTemplate.delete(user);
// }
//}
/**
* 不使用hibernate.cfg.xml
*/
// //继承 HibernateDaoSupport自动生成模板, 必须提供SessionFactory
// public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
// public User findById(Integer id) {
// return this.getHibernateTemplate().get(User.class, id);
// }
// public List<User> findAll() {
// return this.getHibernateTemplate().find("from User");
// }
// public void save(User user) {
// this.getHibernateTemplate().save(user);
// }
// public void update(User user) {
// this.getHibernateTemplate().update(user);
// }
// public void delete(User user) {
// this.getHibernateTemplate().delete(user);
// }
// }
/**
* 使用注解方式
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//User user = new User();
//user.setUsername("fuck");
//user.setPassword("1234");
//String xmlPath = "applicationContext.xml";
//ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
// xmlPath);
//UserService userService = applicationContext.getBean("userService",
// UserService.class);
//userService.saveUser(user);
/*
List<Integer> all = new ArrayList<Integer>();//m取10,n取5;
for(int i=0;i<5;i++)
all.add(i);
Integer j = 5;
Integer[] result = new Integer[5];
Random random = new Random();
for(int i=0;i<5;i++)
result[i] =all.remove(random.nextInt(j--));
for(int i=0;i<5;i++)
private Student student = new Student();
public Student getModel() {
return this.student;
}
// *****************************
private StudentService studentService;
private ChatService chatService;
public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}
public void setChatService(ChatService chatService) {
this.chatService = chatService;
}
public String selectAll() {
List<Student> students = studentService.findAllStudent();
ActionContext.getContext().put("students",students);
return "selectAll";
}
public String beforeUpdate(){
Student student = studentService.findStudentById(this.student.getSid());
ActionContext.getContext().put("student", student);
return "beforeUpdate";
}
public String update(){
this.studentService.updateStudent(student);
return "success";
}
public String delete(){
studentService.deleteStudent(student);
List<Student> students = studentService.findAllStudent();
ActionContext.getContext().put("students", students);
return "selectAll";
}
public String add(){
student.setStatus(1);
try{
this.studentService.saveStudent(student);
}catch(Exception e){
ActionContext.getContext().put("msg","账号已存在,添加失败!");
return "addError";
}
ActionContext.getContext().put("msg","添加成功!");
return "addSuccess";
}
public String read() throws Exception{