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>