JSP内置对象学习案例:在线考试系统
来源:互联网 发布:java员工工资管理系统 编辑:程序博客网 时间:2024/05/21 22:47
答题页显示所有的题目,结果页显示做对了几道题。
代码监护了功能设计,直接将单选多选的标砖答案写在字符串里,通过循环标准答案进行对比,检测出做对的题目数。
<input type="hidden" name="sinans" id="sinansid"/><input type="hidden" name="mulans" id="mulansid"/>
定义了两个隐藏特性的标签。name的属性值为sinans的标签用来存放单选题的答案,属性值为mulans的标签用来存放多选题的答案,通过定义的JavaScript响应事件函数proc()完成。
<script type="text/javascript">function proc(){ var sinans=""; var mulans=""; var topicname=""; //获得单选答案串 var no=1; while(true){ var unit=""; topicname="s"+no; var obj=document.getElementsByName(topicname); if(obj.length==0){ break; } for(var i=0;i<obj.length;i++){ if(obj[i].checked){ unit=obj[i].value; break; } } sinans+=unit; no++; } //获得多选题答案串 no=1; while(true){ var unit=""; topicname="m"+no; var obj=document.getElementsByName(topicname); if(obj.length==0){ break; } for(var i=0;i<obj.length;i++){ if(obj[i].checked){ if(unit=="") unit=obj[i].value; else unit +=obj[i].value; } } mulans+=unit+"-"; no++; } var sinobj=document.getElementById("sinansid"); sinobj.value=sinans; var mulobj=document.getElementById("mulansid"); mulobj.value=mulans; var formobj=document.getElementById("formid"); formobj.submit();}</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><script type="text/javascript">function proc(){ var sinans=""; var mulans=""; var topicname=""; //获得单选答案串 var no=1; while(true){ var unit=""; topicname="s"+no; var obj=document.getElementsByName(topicname); if(obj.length==0){ break; } for(var i=0;i<obj.length;i++){ if(obj[i].checked){ unit=obj[i].value; break; } } sinans+=unit; no++; } //获得多选题答案串 no=1; while(true){ var unit=""; topicname="m"+no; var obj=document.getElementsByName(topicname); if(obj.length==0){ break; } for(var i=0;i<obj.length;i++){ if(obj[i].checked){ if(unit=="") unit=obj[i].value; else unit +=obj[i].value; } } mulans+=unit+"-"; no++; } var sinobj=document.getElementById("sinansid"); sinobj.value=sinans; var mulobj=document.getElementById("mulansid"); mulobj.value=mulans; var formobj=document.getElementById("formid"); formobj.submit();}</script><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>在线考试系统</title></head><body bgcolor="cyan"><div>单选题:<br><p>1+1=()<br><input type="radio" name="s1" value="a"/>0<input type="radio" name="s1" value="b"/>1<input type="radio" name="s1" value="c"/>2<input type="radio" name="s1" value="d"/>3<p>2+2=()<br><input type="radio" name="s2" value="a"/>2<input type="radio" name="s2" value="b"/>4<input type="radio" name="s2" value="c"/>6<input type="radio" name="s2" value="d"/>8<br>多选题:<br><p>()*()=6<br><input type="checkbox" name="m1" value="a"/>2,3<input type="checkbox" name="m1" value="b"/>1,6<input type="checkbox" name="m1" value="c"/>1,3<input type="checkbox" name="m1" value="d"/>3,3<p>()*()=10<br><input type="checkbox" name="m2" value="a"/>2,5<input type="checkbox" name="m2" value="b"/>1,6<input type="checkbox" name="m2" value="c"/>1,10<input type="checkbox" name="m2" value="d"/>3,3<br></div><form action="TestResult.jsp" id="formid"><input type="hidden" name="sinans" id="sinansid"/><input type="hidden" name="mulans" id="mulansid"/><input type="submit" value="提交" onclick="proc()"/></form></body></html>
<%@ 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></head><body> <% String sinright = "cb"; String mulright = "ab-ac"; String sinans = request.getParameter("sinans"); String mulans = request.getParameter("mulans"); int n = 0; for (int i = 0; i < sinans.length(); i++) { if (sinans.charAt(i) == sinright.charAt(i)) n++; } out.print("单选做对了" + n + "个<br>"); n = 0; String unitright[] = mulright.split("-"); String unit[] = mulans.split("-"); for (int i = 0; i < unit.length; i++) { if (unit[i].equals(unitright[i])) { n++; } } out.print("多选做对了" + n + "个"); %></body></html>
阅读全文
0 0
- JSP内置对象学习案例:在线考试系统
- jsp使用session对象模拟在线考试系统
- JSP内置对象之session对象案例
- jsp,web开发的在线考试系统
- JSP内置对象request 常用方法 案例
- JSP内置对象(下)案例
- JSP内置对象requset学习
- jsp学习笔记--内置对象
- JSP内置对象学习笔记
- JSP内置对象学习笔记
- JSP内置对象的学习
- JSP学习之内置对象
- session内置对象JSP学习
- 学习jsp的内置对象
- JSP学习--JSP九大内置对象
- Jsp学习——Jsp内置对象
- JSP学习笔记:初识JSP内置对象
- 有好用的在线考试学习系统?
- Linux下安装/启动/退出/命令行使用Memcached
- 网络请求库(ion、volley、retrofit)和图片加载库(glide、picasso、fresco)
- "-"控件通知到父窗口层处理.
- windows无法连接到group policy client服务.此问题阻止标准用户登陆系统.
- STUN和TURN技术浅析
- JSP内置对象学习案例:在线考试系统
- PHP内核探索:如何执行PHP脚本
- 云集微店开店的优势
- form 中点击button事件
- Android Listview
- Android之Glide(非常好用的图片加载框架)
- lightoj 1341__Aladdin and the Flying Carpet
- 练习(一)
- 图像有用区域