jsp大学作业:jsp编写单选,复选判断题及得分情况
project_1_1.jsp
1 <%@ page contentType="text/html;charset=utf-8" language="java" %> 2 <html> 3 <head> 4 <title>project_1</title> 5 </head> 6 <body> 7 <form action="project_1_2.jsp" method="post" name="form1"> 8 单选题<br> 9 1.application对象所依赖的类或接口是(15`)<br> 10 <input type="radio" name="t1" value="A">A、JspWrite<br> 11 <input type="radio" name="t1" value="B">B、ServletContext<br> 12 <input type="radio" name="t1" value="C">C、PageContext<br> 13 <input type="radio" name="t1" value="D">D、HttpServletContext<br> 14 2.下面说法错误的是(15`)<br> 15 <input type="radio" name="t2" value="A">A、要在JSP网页内直接嵌入一段Java代码,这段代码可以写在script标记对内<br> 16 <input type="radio" name="t2" value="B">B、要在JSP网页内直接嵌入一段Java代码,可以写在标记内<br> 17 <input type="radio" name="t2" value="C">C、JSP代码中变量和方法的声明是写在标记内<br> 18 <input type="radio" name="t2" value="D">D、以上说法都正确<br> 19 多选题<br> 20 3.下面关于session的用法哪个不是正确的?(20`)<br> 21 <input type="checkbox" name="t3" value="A">A、HttpSession session = new HttpSession()<br> 22 <input type="checkbox" name="t3" value="B">B、String haha =session.getParameter(“haha”)<br> 23 <input type="checkbox" name="t3" value="C">C、session.removeAttribute(“haha”)<br> 24 <input type="checkbox" name="t3" value="D">D、session. setAttribute(“haha”)<br> 25 4.以下关于HTML表单的叙述正确的是(20`)<br> 26 <input type="checkbox" name="t4" value="A">A、表单按钮和表单文本框的标记都是用input标记定义<br> 27 <input type="checkbox" name="t4" value="B">B、GET表单提交方式较POST方式快速//速度:显然Get比Post要快。<br> 28 <input type="checkbox" name="t4" value="C">C、POST表单提交方式把数据链接在目标资源的URL中,而GET方式把表 单数据存储在HTTP请求报头的尾部<br> 29 <input type="checkbox" name="t4" value="D">D、同名复选框可向服务器传递0个或多个数据值,而同名单选按钮只能向 服务器传递1个数据值。<br> 30 5.(1)jsp:forward动作用来把当前的JSP页面重导到另一个页面上,用户看到的地址是当前页面的地址,而内容是另一个页面的。(15`)<br> 31 <input type="radio" name="t5" value="true">对<br> 32 <input type="radio" name="t5" value="false">错<br> 33 (2)jsp:param动作可单独使用,用于页面间传递参数。(15`)<br> 34 <input type="radio" name="t6" value="true">对<br> 35 <input type="radio" name="t6" value="false">错<br> 36 <input type="submit" value="提交" name="submit"> 37 <input type="reset" value="重置"> 38 </form> 39 </body> 40 </html>
project_1_2.jsp
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 <html> 3 <head> 4 <title>得分情况</title> 5 </head> 6 <body> 7 <%! 8 int sum = 0;//总分 9 %> 10 <% 11 String t1 = request.getParameter("t1"); 12 String t2 = request.getParameter("t2"); 13 String t3[] = request.getParameterValues("t3"); 14 String t4[] = request.getParameterValues("t4"); 15 String t5 = request.getParameter("t5"); 16 String t6 = request.getParameter("t6"); 17 18 //说明答案 19 out.print("第一题答案为B,你选择的答案为" + t1); 20 if (t1 == null) { 21 out.print("\t回答错误不得分"); 22 } else if (t1.equals("B")) { 23 sum = sum + 15; 24 out.print("\t得分:15分"); 25 } else { 26 out.print("\t回答错误不得分"); 27 } 28 %><br><% 29 out.print("第二题答案为A,你选择的答案为" + t2); 30 if (t2 == null) { 31 out.print("\t回答错误不得分"); 32 } else if (t2.equals("A")) { 33 sum = sum + 15; 34 out.print("\t得分:15分"); 35 } else { 36 out.print("\t回答错误不得分"); 37 } 38 %><br><% 39 out.print("第三题答案为ABD,你选择的答案为"); 40 if (t3 == null) { 41 out.print("null\t回答错误不得分"); 42 }else { 43 for (String s : t3) { 44 out.print(s); 45 } 46 if (t3.length == 1 || t3.length == 2 || t3.length == 4) { 47 out.print("\t回答错误不得分"); 48 } else if (t3.length == 3) { 49 if (t3[0].equals("A") && t3[1].equals("B") && t3[2].equals("D")) { 50 sum = sum + 20; 51 out.print("\t得分:20分"); 52 } else { 53 out.print("\t回答错误不得分"); 54 } 55 } else { 56 out.print("\t回答错误不得分"); 57 } 58 } 59 %><br><% 60 out.print("第四题答案为ACD,你选择的答案为"); 61 if (t4 == null) { 62 out.print("null\t回答错误不得分"); 63 }else { 64 for (String s : t4) { 65 out.print(s); 66 } 67 if (t3.length == 1 || t3.length == 2 || t3.length == 4) { 68 out.print("\t回答错误不得分"); 69 } else if (t3.length == 3) { 70 if (t4[0].equals("A") && t4[1].equals("C") && t4[2].equals("D")) { 71 sum = sum + 20; 72 out.print("\t得分:20分"); 73 } else { 74 out.print("\t回答错误不得分"); 75 } 76 } 77 } 78 %><br><% 79 out.print("第五题答案为false,你选择的答案为" + t5); 80 if (t1 == null) { 81 out.print("\t回答错误不得分"); 82 } else if (t5.equals("false")) { 83 sum = sum + 15; 84 out.print("\t得分:15分"); 85 } else { 86 out.print("\t回答错误不得分"); 87 } 88 %><br><% 89 out.print("第六题答案为false,你选择的答案为" + t5); 90 if (t1 == null) { 91 out.print("\t回答错误不得分"); 92 } else if (t6.equals("true")) { 93 sum = sum + 15; 94 out.print("\t得分:15分"); 95 } else { 96 out.print("\t回答错误不得分"); 97 } 98 %><br><% 99 out.print("总分为" + sum); 100 %> 101 </body> 102 </html>
昔日我曾苍老,如今风华正茂(ง •̀_•́)ง