基于javaweb+mysql的ssh课程资源教学在线考试平台(java+ssh+mysql+jsp+tomcat)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的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等等。
<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>
<tr align="center">
<td>试题描述</td>
<td colspan="7"><input type="text" name="description" value="${requestScope.question.description}" class="form-control"></td>
</tr>
<s:if test="#request.question.type=='single'||#request.question.type=='multiple'">
<tr align="center">
<td>选项A</td>
<td colspan="7"><input type="text" name="option1" value="${requestScope.question.option1}" class="form-control"></td>
</tr>
<tr align="center">
<td>选项B</td>
<td colspan="7"><input type="text" name="option2" value="${requestScope.question.option2}" class="form-control"></td>
</tr>
<tr align="center">
<td>选项C</td>
<td colspan="7"><input type="text" name="option3" value="${requestScope.question.option3}" class="form-control"></td>
</tr>
<tr align="center">
<td>选项D</td>
<td colspan="7"><input type="text" name="option4" value="${requestScope.question.option4}" class="form-control"></td>
</tr>
</s:if>
<s:if test="#request.question.type=='single'">
<tr>
answer_r=questionService.findQuestionById(qid).getAnswer();
if(answer_r.equals(answer_m)){
scores1+=qpService.findQPById(qid, pid).getScore();
}
}
//处理多选题
Integer size2 = Integer.parseInt(request.getParameter("size2"));
for(int i=0;i<size2;i++){
qid=Integer.parseInt(request.getParameter("qids2"+i));
String[] temp=request.getParameterValues("answers2"+i);
answer_m=temp[0];
for(int j=1;j<temp.length;j++)
answer_m=answer_m+", "+temp[j];
myAnswer.setQid(qid);
myAnswer.setAnswer(answer_m);
myAnswerService.saveMyAnswer(myAnswer);
answer_r=questionService.findQuestionById(qid).getAnswer();
if(answer_r.equals(answer_m)){
scores1+=qpService.findQPById(qid, pid).getScore();
}
}
//处理判断题
Integer size3 = Integer.parseInt(request.getParameter("size3"));
for(int i=0;i<size3;i++){
qid=Integer.parseInt(request.getParameter("qids3"+i));
answer_m=request.getParameter("answers3"+i);
myAnswer.setQid(qid);
myAnswer.setAnswer(answer_m);
myAnswerService.saveMyAnswer(myAnswer);
answer_r=questionService.findQuestionById(qid).getAnswer();
if(answer_r.equals(answer_m)){
scores1+=qpService.findQPById(qid, pid).getScore();
}
}
//处理解答题
if(qids4.size()==0){
exam.setStatus(3);
exam.setScore2(0);
exam.setScore3(scores1);
}
else{
List<Course> courses = courseService.findAllCourse();
ActionContext.getContext().put("courses",courses);
List<Question> qs_si_e = questionService.findQuestionByTD("single", "1",paper.getCourse().getCid());
List<Question> qs_si_m = questionService.findQuestionByTD("single", "2",paper.getCourse().getCid());
List<Question> qs_si_d = questionService.findQuestionByTD("single", "3",paper.getCourse().getCid());
System.out.print("单选题"+qs_si_e.size()+";"+qs_si_m.size()+";"+qs_si_d.size());
if(si_e_n>qs_si_e.size()||si_m_n>qs_si_m.size()||si_d_n>qs_si_d.size()){
ActionContext.getContext().put("msg", "题库中没有足够的满足条件的单选题");
return "generateFalse";
}
List<Question> qs_m_e = questionService.findQuestionByTD("multiple", "1",paper.getCourse().getCid());
List<Question> qs_m_m = questionService.findQuestionByTD("multiple", "2",paper.getCourse().getCid());
List<Question> qs_m_d = questionService.findQuestionByTD("multiple", "3",paper.getCourse().getCid());
if(m_e_n>qs_m_e.size()||m_m_n>qs_m_m.size()||m_d_n>qs_m_d.size()){
ActionContext.getContext().put("msg", "题库中没有足够的满足条件的多选题");
return "generateFalse";
}
List<Question> qs_j_e = questionService.findQuestionByTD("judgment", "1",paper.getCourse().getCid());
List<Question> qs_j_m = questionService.findQuestionByTD("judgment", "2",paper.getCourse().getCid());
List<Question> qs_j_d = questionService.findQuestionByTD("judgment", "3",paper.getCourse().getCid());
System.out.print("判断题"+qs_j_e.size()+";"+qs_j_m.size()+";"+qs_j_d.size());
if(j_e_n>qs_j_e.size()||j_m_n>qs_j_m.size()||j_d_n>qs_j_d.size()){
ActionContext.getContext().put("msg", "题库中没有足够的满足条件的判断题");
List<Course> cs = (List<Course>)ActionContext.getContext().get("courses");
System.out.println("测试"+cs.size());
return "generateFalse";
}
List<Question> qs_su_e = questionService.findQuestionByTD("subject", "1",paper.getCourse().getCid());
List<Question> qs_su_m = questionService.findQuestionByTD("subject", "2",paper.getCourse().getCid());
List<Question> qs_su_d = questionService.findQuestionByTD("subject", "3",paper.getCourse().getCid());
if(su_e_n>qs_su_e.size()||su_m_n>qs_su_m.size()||su_d_n>qs_su_d.size()){
ActionContext.getContext().put("msg", "题库中没有足够的满足条件的解答题题");
return "generateFalse";
}
paper.setStatus(1);
Course course = courseService.findCourseById(paper.getCourse().getCid());
paper.setName(paper.getYear()+paper.getTerm()+course.getName()+"课程"+paper.getType()+"试卷");
paperService.savePaper(paper);
Integer pid=paper.getPid();
Integer[] single1=generateRandom(si_e_n,qs_si_e.size());
for(int i=0;i<si_e_n;i++){
qpService.saveQP(new QP(qs_si_e.get(single1[i]).getQid(),pid,si_e_s));
}
Integer[] single2=generateRandom(si_m_n,qs_si_m.size());
for(int i=0;i<si_m_n;i++){
qpService.saveQP(new QP(qs_si_m.get(single2[i]).getQid(),pid,si_m_s));
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";
}
}
public String beforChat() {
Teacher teacher = teacherService.findTeacherById(this.teacher.getTid());
List<Teacher> teachers = teacherService.findAllTeacher();
Student student = (Student)ActionContext.getContext().getSession().get("student");
List<Chat> chats = chatService.findChatByTS(teacher.getTid(), student.getSid());
ActionContext.getContext().put("teacher", teacher);
ActionContext.getContext().put("teachers", teachers);
ActionContext.getContext().put("chats", chats);
return "beforChat";
}
public String addChat() {
Teacher teacher = teacherService.findTeacherById(this.teacher.getTid());
Student student = (Student)ActionContext.getContext().getSession().get("student");
Chat chat = new Chat();
chat.setContent(content);
chat.setStudent(student);
chat.setTeacher(teacher);
chat.setDirection(1);
chat.setTime(new Date());
chatService.saveChat(chat);
if(teacher.getStatus()==1){
SystemMail.sendMail(teacher.getEmail(), teacher.getName(), student.getName(), 1);
}
List<Teacher> teachers = teacherService.findAllTeacher();
List<Chat> chats = chatService.findChatByTS(teacher.getTid(), student.getSid());
ActionContext.getContext().put("teacher", teacher);
ActionContext.getContext().put("teachers", teachers);
ActionContext.getContext().put("chats", chats);
return "beforChat";
}
List<Question> qs_j_m = questionService.findQuestionByTD("judgment", "2",paper.getCourse().getCid());
List<Question> qs_j_d = questionService.findQuestionByTD("judgment", "3",paper.getCourse().getCid());
System.out.print("判断题"+qs_j_e.size()+";"+qs_j_m.size()+";"+qs_j_d.size());
if(j_e_n>qs_j_e.size()||j_m_n>qs_j_m.size()||j_d_n>qs_j_d.size()){
ActionContext.getContext().put("msg", "题库中没有足够的满足条件的判断题");
List<Course> cs = (List<Course>)ActionContext.getContext().get("courses");
System.out.println("测试"+cs.size());
return "generateFalse";
}
List<Question> qs_su_e = questionService.findQuestionByTD("subject", "1",paper.getCourse().getCid());
List<Question> qs_su_m = questionService.findQuestionByTD("subject", "2",paper.getCourse().getCid());
List<Question> qs_su_d = questionService.findQuestionByTD("subject", "3",paper.getCourse().getCid());
if(su_e_n>qs_su_e.size()||su_m_n>qs_su_m.size()||su_d_n>qs_su_d.size()){
ActionContext.getContext().put("msg", "题库中没有足够的满足条件的解答题题");
return "generateFalse";
}
paper.setStatus(1);
Course course = courseService.findCourseById(paper.getCourse().getCid());
paper.setName(paper.getYear()+paper.getTerm()+course.getName()+"课程"+paper.getType()+"试卷");
paperService.savePaper(paper);
Integer pid=paper.getPid();
Integer[] single1=generateRandom(si_e_n,qs_si_e.size());
for(int i=0;i<si_e_n;i++){
qpService.saveQP(new QP(qs_si_e.get(single1[i]).getQid(),pid,si_e_s));
}
Integer[] single2=generateRandom(si_m_n,qs_si_m.size());
for(int i=0;i<si_m_n;i++){
qpService.saveQP(new QP(qs_si_m.get(single2[i]).getQid(),pid,si_m_s));
}
Integer[] single3=generateRandom(si_d_n,qs_si_d.size());
for(int i=0;i<si_d_n;i++){
qpService.saveQP(new QP(qs_si_d.get(single3[i]).getQid(),pid,si_d_s));
}
Integer[] multiple1=generateRandom(m_e_n,qs_m_e.size());
for(int i=0;i<m_e_n;i++){
qpService.saveQP(new QP(qs_m_e.get(multiple1[i]).getQid(),pid,m_e_s));
}
Integer[] multiple2=generateRandom(m_m_n,qs_m_m.size());
for(int i=0;i<m_m_n;i++){
List<Question> questions1 = questionService.findQuestionInQP(paper.getPid());
List<Question> questions2 = questionService.findQuestionOutQP(paper.getPid());
List<Course> courses = courseService.findAllCourse();
ActionContext.getContext().put("paper", paper);
ActionContext.getContext().put("questions1", questions1);
ActionContext.getContext().put("questions2", questions2);
ActionContext.getContext().put("courses", courses);
return "generatePaper";
}
public String addQP(){
QP qp = new QP();
qp.setPid(this.paper.getPid());
qp.setQid(qid);
qp.setScore(0);
qpService.saveQP(qp);
Paper paper = paperService.findPaperById(this.paper.getPid());
List<Question> questions1 = questionService.findQuestionInQP(paper.getPid());
List<Question> questions2 = questionService.findQuestionOutQP(paper.getPid());
List<Course> courses = courseService.findAllCourse();
ActionContext.getContext().put("paper", paper);
ActionContext.getContext().put("questions1", questions1);
ActionContext.getContext().put("questions2", questions2);
ActionContext.getContext().put("courses", courses);
return "generatePaper";
}
public String filter(){
//System.out.print("试卷号"+paper.getPid()+";"+"课程号"+cid+";"+"题型"+type+";");
Paper paper = paperService.findPaperById(this.paper.getPid());
List<Question> questions1 = questionService.findQuestionInQP(paper.getPid());
List<Question> questions2 = questionService.findQuestionOutQPBy(paper.getPid(), cid, type);
List<Course> courses = courseService.findAllCourse();
ActionContext.getContext().put("paper", paper);
ActionContext.getContext().put("questions1", questions1);
ActionContext.getContext().put("questions2", questions2);
ActionContext.getContext().put("courses", courses);
return "generatePaper";
}
public String beforeUpdateScore(){
Paper paper = paperService.findPaperById(this.paper.getPid());
List<Question> questions = questionService.findQuestionInQP(paper.getPid());
for(Question q:questions){
System.out.println("编号:"+q.getQid());
}
ActionContext.getContext().put("paper", paper);
ActionContext.getContext().put("questions", questions);
examService.updateExam(exam);
Integer pid = paper.getPid();
Integer qid = new Integer(0);
Integer scores1 = new Integer(0);
String answer_r,answer_m;
MyAnswer myAnswer = new MyAnswer();
myAnswer.setEid(exam.getEid());
HttpServletRequest request = ServletActionContext.getRequest();
//处理单选题
Integer size1 = Integer.parseInt(request.getParameter("size1"));
for(int i=0;i<size1;i++){
qid=Integer.parseInt(request.getParameter("qids1"+i));
answer_m=request.getParameter("answers1"+i);
myAnswer.setQid(qid);
myAnswer.setAnswer(answer_m);
myAnswerService.saveMyAnswer(myAnswer);
answer_r=questionService.findQuestionById(qid).getAnswer();
if(answer_r.equals(answer_m)){
scores1+=qpService.findQPById(qid, pid).getScore();
}
}
//处理多选题
Integer size2 = Integer.parseInt(request.getParameter("size2"));
for(int i=0;i<size2;i++){
qid=Integer.parseInt(request.getParameter("qids2"+i));
String[] temp=request.getParameterValues("answers2"+i);
answer_m=temp[0];
for(int j=1;j<temp.length;j++)
answer_m=answer_m+", "+temp[j];
myAnswer.setQid(qid);
myAnswer.setAnswer(answer_m);
myAnswerService.saveMyAnswer(myAnswer);
answer_r=questionService.findQuestionById(qid).getAnswer();
if(answer_r.equals(answer_m)){
scores1+=qpService.findQPById(qid, pid).getScore();
}
}
//处理判断题
Integer size3 = Integer.parseInt(request.getParameter("size3"));
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{
InputStream is = new FileInputStream(file);
String uploadPath = ServletActionContext.getServletContext().getRealPath("/temp");
System.out.println(uploadPath);
File toFile = new File(uploadPath,this.getFileFileName());
OutputStream os = new FileOutputStream(toFile);
byte[] buffer = new byte[1024];
List<Course> courses = courseService.findAllCourse();
ActionContext.getContext().put("paper", paper);
ActionContext.getContext().put("questions1", questions1);
ActionContext.getContext().put("questions2", questions2);
ActionContext.getContext().put("courses", courses);
return "generatePaper";
}
public String filter(){
//System.out.print("试卷号"+paper.getPid()+";"+"课程号"+cid+";"+"题型"+type+";");
Paper paper = paperService.findPaperById(this.paper.getPid());
List<Question> questions1 = questionService.findQuestionInQP(paper.getPid());
List<Question> questions2 = questionService.findQuestionOutQPBy(paper.getPid(), cid, type);
List<Course> courses = courseService.findAllCourse();
ActionContext.getContext().put("paper", paper);
ActionContext.getContext().put("questions1", questions1);
ActionContext.getContext().put("questions2", questions2);
ActionContext.getContext().put("courses", courses);
return "generatePaper";
}
public String beforeUpdateScore(){
Paper paper = paperService.findPaperById(this.paper.getPid());
List<Question> questions = questionService.findQuestionInQP(paper.getPid());
for(Question q:questions){
System.out.println("编号:"+q.getQid());
}
ActionContext.getContext().put("paper", paper);
ActionContext.getContext().put("questions", questions);
return "beforeUpdateScore";
}
public String selectUnfinished(){
Student student = (Student)ActionContext.getContext().getSession().get("student");
List<Paper> papers = paperService.findPaperOutExam(student.getSid());
ActionContext.getContext().put("papers", papers);
return "selectUnfinished";
}
public String selectFinished(){
<!-- 自定义js -->
<!-- 第三方插件 -->
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'updateQuestion.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="css/animate.css" rel="stylesheet">
<link href="css/style.css?v=4.1.0" rel="stylesheet">
<script type="text/javascript">
function checkForm(f){
var type = "${requestScope.question.type}";
var course = document.getElementById("course");
if(f.description.value==""){
alert("题目描述不能为空!!");
f.description.focus();
return false;
}
if(type=="single"||type=="multiple"){
if(f.option1.value==""){
alert("选项A不能为空!!");
Integer eid = examService.findExamBySP(sid, pid).getEid();
List<String> answers_m = new ArrayList<String>();
List<Integer> scores_r = new ArrayList<Integer>();
List<Question> questions = questionService.findQuestionInQPByType(pid, "subject");
for(Question q:questions){
String answer_m = myAnswerService.findMyAnswerByQE(q.getQid(), eid).getAnswer();
Integer score = qpService.findQPById(q.getQid(),pid).getScore();
answers_m.add(answer_m);
scores_r.add(score);
}
ActionContext.getContext().put("questions", questions);
ActionContext.getContext().put("answers_m", answers_m);
ActionContext.getContext().put("scores_r", scores_r);
ActionContext.getContext().put("pid", pid);
ActionContext.getContext().put("sid", sid);
return "markPaper";
}
public String autoGenerate(){
HttpServletRequest request = ServletActionContext.getRequest();
//单选题组卷相关参数
Integer si_e_n = Integer.parseInt(request.getParameter("si_e_n"));
Integer si_e_s = Integer.parseInt(request.getParameter("si_e_s"));
Integer si_m_n = Integer.parseInt(request.getParameter("si_m_n"));
Integer si_m_s = Integer.parseInt(request.getParameter("si_m_s"));
Integer si_d_n = Integer.parseInt(request.getParameter("si_d_n"));
Integer si_d_s = Integer.parseInt(request.getParameter("si_d_s"));
//多选题组卷相关参数
Integer m_e_n = Integer.parseInt(request.getParameter("m_e_n"));
Integer m_e_s = Integer.parseInt(request.getParameter("m_e_s"));
Integer m_m_n = Integer.parseInt(request.getParameter("m_m_n"));
Integer m_m_s = Integer.parseInt(request.getParameter("m_m_s"));
Integer m_d_n = Integer.parseInt(request.getParameter("m_d_n"));
Integer m_d_s = Integer.parseInt(request.getParameter("m_d_s"));
//判断题组卷相关参数
Integer j_e_n = Integer.parseInt(request.getParameter("j_e_n"));
Integer j_e_s = Integer.parseInt(request.getParameter("j_e_s"));
Integer j_m_n = Integer.parseInt(request.getParameter("j_m_n"));
Integer j_m_s = Integer.parseInt(request.getParameter("j_m_s"));
Integer j_d_n = Integer.parseInt(request.getParameter("j_d_n"));
Integer j_d_s = Integer.parseInt(request.getParameter("j_d_s"));
//解答题组卷相关参数
Integer su_e_n = Integer.parseInt(request.getParameter("su_e_n"));
Integer su_e_s = Integer.parseInt(request.getParameter("su_e_s"));
Integer su_m_n = Integer.parseInt(request.getParameter("su_m_n"));
Integer su_m_s = Integer.parseInt(request.getParameter("su_m_s"));
Integer su_d_n = Integer.parseInt(request.getParameter("su_d_n"));
Integer su_d_s = Integer.parseInt(request.getParameter("su_d_s"));
List<Course> courses = courseService.findAllCourse();
<a class="J_menuItem" href="paperAction_selectAll">查询所有试卷</a>
</li>
<li>
<a class="J_menuItem" href="courseAction_beforeGenerate">自动组卷</a>
</li>
<li>
<a class="J_menuItem" href="courseAction_beforeAddPaper">手动组卷</a>
</li>
</ul>
</li>
<li>
<a class="J_menuItem" href="themeAction_selectAllForA">
<i class="fa fa-globe"></i>
<span class="nav-label">论坛管理</span>
</a>
</li>
</ul>
</div>
</nav>
<!--左侧导航结束-->
<!--右侧部分开始-->
<div id="page-wrapper" class="gray-bg dashbard-1">
<div class="row border-bottom">
<nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
<!-- <div class="navbar-header">-->
<button class="navbar-minimalize minimalize-styl-2 btn btn-info">
<i class="fa fa-bars"></i>
</button>
<!-- </div>-->
<!-- <ul class="nav navbar-top-links navbar-right">-->
<ul class="nav navbar-top-links navbar-right">
<li><a class="J_menuItem" href="admin/updateAdminInfo.jsp"><i class="fa fa-user-secret"></i>${sessionScope.admin.name},您好!</a></li>
<li><a href="loginAction_logoff?identity=admin">注销 <i class="fa fa-share-square-o"></i></a></li>
<!-- <li class="dropdown navbar-right">
<a class="dropdown-toggle count-info" data-toggle="dropdown" href="#">
${sessionScope.admin.name}
<i class="fa fa-cog"></i>
</a>
<ul class="dropdown-menu">
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++)
System.out.println(result[i]);
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 "beforeUpdate";
}
public String update() {
this.homeworkService.updateHomework(homework);
return "success";
}
public String delete() {
homeworkService.deleteHomework(homework);
List<Homework> homeworks = homeworkService.findAllHomework();
ActionContext.getContext().put("homeworks", homeworks);
/**
* 使用注解方式
*/
@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.save(student);
}
public void update(Student student) {
String password=st.getCell(1, i).getContents();
String name=st.getCell(2, i).getContents();
String schoolclass=st.getCell(3, i).getContents();
String phone=st.getCell(4, i).getContents();
String email=st.getCell(5, i).getContents();
students.add(new Student(sid,password,name,schoolclass,phone,email));
}
}catch(Exception e){
e.printStackTrace();
}
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) {