开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
public static final int Q_TYPE_FILL_BLANK = 2;
public static final int Q_TYPE_JUDGE = 3;
public static final int Q_TYPE_WRITE = 4;
public static final String PAGE_NAME_PREFIX_CHOICE = "choice_";
public static final String PAGE_NAME_PREFIX_FILLBLANK = "fillblank_";
public static final String PAGE_NAME_PREFIX_JUDGE = "judge_";
public static final String PAGE_NAME_PREFIX_WRITE = "write_";
public static final String USER_ROLE_STU = "1";
public static final String USER_ROLE_ADMIN = "2";
}
<%@ 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">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>试题一览</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
rel="stylesheet">
<script
<h1>
<div class="label label-primary">
选择题 <span class="badge">${fn:length(paper.choices)}</span>
</div>
</h1>
<c:forEach items="${paper.choices}" var="q" varStatus="var">
<xmp>${var.count}.${q.q.title}</xmp>
<br>
<input type="checkbox" name="choice_${var.count}" value="A" />A.
<xmp>${q.q.optiona}</xmp>
<br>
<input type="checkbox" name="choice_${var.count}" value="B" />B.
<xmp>${q.q.optionb}</xmp>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<label class="radio-inline"> <input type="radio"
name="role" value="1" checked>学生
</label>
<label class="radio-inline"> <input type="radio"
name="role" value="2" checked>教师
</label>
</div>
</div>
<!-- ********************************************** -->
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<span id="helpBlock2" class="help-block">${loginMsg}</span>
<button type="submit" class="btn btn-success btn-lg btn-block">进入系统</button>
</div>
</div>
</form>
</div>
<div class="col-lg-3"></div>
</div>
</div>
</body>
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>在线考试系统</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
rel="stylesheet">
<script
src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
</head>
this.answer = answer;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getUserAnswer() {
return userAnswer;
</div>
</form>
</div>
<div class="col-lg-3"></div>
</div>
</div>
</body>
</html>
<%@ 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" %>
<!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="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
rel="stylesheet">
<script
src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<br>
选项A:
<input type="text" name="optiona" class="form-control" value=${question.optiona}>
<br>
选项B:
<input type="text" name="optionb" class="form-control" value=${question.optionb}>
<br>
选项C:
<input type="text" name="optionc" class="form-control" value=${question.optionc}>
<br>
选项D:
<input type="text" name="optiond" class="form-control" value=${question.optiond}>
</div>
<hr>
标准答案:
<textarea name="answer" class="form-control" rows="10">${question.answer}</textarea>
<button type="submit" class="btn btn-default">提交</button>
</form>
</div>
<div class="col-lg-3"></div>
</div>
<script>
m.addAttribute("paperResult", html);
// - 保存进数据库
service.save(paperAnswer, list);
return Const.PAGE_STUDENT_RESULT;
}
private void setUserAnswer(String paraName, String typePrefix, List<QuestionPlus> qList, String userAnswer) {
// 获取试题原始对象
int len = typePrefix.length();
String i = paraName.substring(len);
int paperId = Integer.parseInt(i);// 试题编号
int index = paperId - 1;
QuestionPlus qq = qList.get(index);
// 设置题目编号
qq.setPaperId(paperId);
// 设置用户答案
qq.setStuAnswer(userAnswer);
qList.set(index, qq);
}
PaperAnswer pa = paperAnswerMapper.selectByPrimaryKey(id);
Example example = new Example(PaperSubjectiveAnswer.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("paperId", id);
List<PaperSubjectiveAnswer> selectByExample = stuAnswerMapper.selectByExample(example);
for (PaperSubjectiveAnswer psa : selectByExample) {
pa.addList(psa);
}
return pa;
}
}
package demo.controller;
import java.util.List;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import demo.vo.Question;
import demo.vo.QuestionPaper;
private String scoreCalc() {
StringBuffer sb = new StringBuffer();
if (choices.size() != 0) {
sb.append("<br>选择题正确率:" + (double) rightChoices / choices.size());
}
if (fillblanks.size() != 0) {
sb.append("<br>填空题正确率:" + (double) rightFillblanks / fillblanks.size());
}
if (judgements.size() != 0) {
sb.append("<br>判断题正确率:" + (double) rightJudgements / judgements.size());
}
if ((choices.size() + fillblanks.size() + judgements.size()) != 0) {
sb.append("<br>综合正确率:" + (double) (rightChoices + rightFillblanks + rightJudgements)
/ (choices.size() + fillblanks.size() + judgements.size()));
}
return sb.toString();
}
public String getCurrentResult(PaperAnswer paperAnswer, List<PaperSubjectiveAnswer> stuAnswerList) {
// 变量初始化
rightChoices = rightFillblanks = rightJudgements = 0;
StringBuffer sb = new StringBuffer();
// 客觀題答題結果
sb.append(foreachList(choices));
sb.append(foreachList(fillblanks));
sb.append(foreachList(judgements));
运行环境
Java≥8、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JSP JavaScript Bootstrap SpringBoot SpringMVC MyBatis
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
教师:查看考试结果、编辑考试题目
学生:考试答题
老师
学生