test.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Test</title> <style type="text/css"> p{text-indent: 2em;font-size: 16px;} </style> </head> <body> <form method="post" action="test.jsp"> <h1>请回答下面的问题:</h1> <p> 1、在北京召开的奥运会时第29届奥运会? <input type="radio" name="quest1" value="1">正确 <input type="radio" name="quest1" value="2">错误 </p> <p> 2、windows操作系统是哪个公司的产品? <input type="radio" name="quest2" value="1">Sun公司 <input type="radio" name="quest2" value="2">IBM公司 <input type="radio" name="quest2" value="3">Mcrosoft公司 </p> <p> 3、下面的程序设计语言,那些事面向对象的? <input type="checkbox" name="quest3" value="1">Java语言 <input type="checkbox" name="quest3" value="2">C语言 <input type="checkbox" name="quest3" value="3">C++语言 </p> <p> 4、编写Servlet程序应继承什么类? <input type="text" name="quest4" size="30"> </p> <p> <b>交卷请点击</b> <input type="submit" name="submit"> <b>重答请点击</b> <input type="reset" name="reset"> </p> </form> </body> </html>
test.jsp
<%@ 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>Test</title> </head> <body> <% int score = 0; request.setCharacterEncoding("UTF-8"); String quest1 = request.getParameter("quest1"); String quest2 = request.getParameter("quest2"); String []quest3 = request.getParameterValues("quest3"); String quest4 = request.getParameter("quest4"); if(quest1 != null && quest1.equals("1")) { score += 25; } if(quest2 != null && quest2.equals("3")) { score += 25; } if(quest3 != null && quest3[0].equals("1") && quest3[1].equals("3")) { score += 25; } if(quest4 != null && quest4.equals("HttpServlet")) { score += 25; } out.println("您的分数为:" + score); %> </body> </html>