设计一个简单的网上答题与评测系统,该程序包括两部分,首先是试题页面的设计及其解答的提交,其次是当提交解答后,系统自动评阅并给出评阅结果。
提交信息页面。input.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head><title>简单的网上试题自动评测--试题</title>
<body>
<form action="show.jsp" method="post">
一、2+3=?<br>
<input type="radio" name="r1" value="2" checked="checked">2
<input type="radio" name="r1" value="3">3
<input type="radio" name="r1" value="4">4
<input type="radio" name="r1" value="5">5<br>
二、下列哪些是偶数?<br>
<input type="checkbox" name="c1"value="2">2
<input type="checkbox" name="c1"value="3">3
<input type="checkbox" name="c1"value="4">4
<input type="checkbox" name="c1"value="5">5<br>
三、下列哪些是动态网页?<br>
<select size="4" name="list1" multiple="multiple">
<option value="asp">ASP</option>
<option value="php">PHP</option>
<option value="htm">HTML</option>
<option value="jsp">JSP</option>
<option value="xyz" selected="selected">xyz</option>
</select><br>
四、下列组件哪个是服务器端的?<br>
<select size="1" name="list5">
<option value="jsp">JSP</option>
<option value="servlet">SERVLET</option>
<option value="java">JAVA</option>
<option value="jdbc">JDBC</option>
</select><br>
五、在服务器端用来接收用户请求的对象是:
<input type="text" size="20" name="text1"><br>
<div align="left">
<blockquote>
<input type="submit" value="提交" name="button1">
<input type="reset" value="重置" name="button2">
</blockquote>
</div>
</form>
</body>
</html>
获取提交信息并进行处理显示结果页面。show.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>简单的网上试题自动评测--评测</title>
</head>
<body>
<%String s1=request.getParameter("r1");
if(s1!=null){
out.println("一、解答为:2+3="+s1+" ");
if(s1.equals("5"))out.println("正确"+"<br>");
else out.println("错误"+"<br>");
}else out.println("一、没有解答");
out.println("--------------------<br>");
String[] s21=request.getParameterValues("c1");
if(s21!=null){
out.println("二、解答为:偶数有:");
for(int i=0;i<s21.length;++i){
out.println(s21[i]+" ");
}
if(s21.length==2&&s21[0].equals("2")&&s21[1].equals("4"))
out.println("正确"+"<br>");
else
out.println("错误"+"<br>");
}else out.println("二、没有解答!");
out.println("--------------------<br>");
String[] s31=request.getParameterValues("list1");
if(s31!=null){
out.println("三、解答为:动态网页有:");
for(int i=0;i<s31.length;++i){
out.println(s31[i]+" ");
}
if(s31.length==3&&s31[0].equals("asp")&&s31[1].equals("php")&&s31[2].equals("jsp"))
out.println("正确"+"<br>");
else
out.println("错误"+"<br>");
}else out.println("三、没有解答!");
out.println("--------------------<br>");
String s4=request.getParameter("list5");
if(s4!=null){
out.println("四、解答为:服务器端的组件是有:");
out.println(s4+" ");
if(s4!=null&&s4.equals("servlet"))
out.println("正确"+"<br>");
else
out.println("错误"+"<br>");
}else out.println("四、没有解答!");
out.println("--------------------<br>");
String s5=request.getParameter("text1");
if(s5!=null){
out.println("五、解答为:");
out.println(s5+" ");
if(s5!=null&&s5.equals("request"))
out.println("正确"+"<br>");
else
out.println("错误"+"<br>");
}else out.println("五、没有解答!");
out.println("--------------------<br>");
%>
</body>
</html>