main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>測試</title>
</head>
<body>
<form action="action.jsp" method="post" name="form">
<table>
<tr><td>request是幹嘛的?</td></tr>
<tr>
<td>
<input type="radio" name="1" value=1>A.響應請求
<input type="radio" name="1" value=2>B.取得資料與資訊
<input type="radio" name="1" value=3>C.輸出資料
<input type="radio" name="1" value=4>D.鈍角
</td>
</tr>
<tr><td><br>respond是幹嘛的?</td></tr>
<tr>
<td>
<input type="radio" name="2" value=1>A.響應客戶端資訊
<input type="radio" name="2" value=2>B.資料匯入
<input type="radio" name="2" value=3>C.表示當前網頁
<input type="radio" name="2" value=4>D.資料輸出
</td>
</tr>
<tr><td><br>下列那個屬於9個內建物件</td></tr>
<tr>
<td>
<input type="radio" name="3" value=1>A.out
<input type="radio" name="3" value=2>B.int
<input type="radio" name="3" value=3>C.forward
<input type="radio" name="3" value=4>D.post
</td>
</tr>
<tr>
<td><input type="submit" name="submit" value="開始傳輸"></td>
</tr>
</table>
</form>
</body>
</html>
action.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.lang.Math"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>計算結果</title>
</head>
<body>
<%!int a=0; %>
<%
a=0;
String t1=request.getParameter("1");
String t2=request.getParameter("2");
String t3=request.getParameter("3");
if(Integer.parseInt(t1)==2) a++;
if(Integer.parseInt(t2)==1) a++;
if(Integer.parseInt(t3)==1) a++;
%>
<p>正確答案:1.B 2.A 3.A
<P>你的選擇:1.<%= (char) (64 + Integer.parseInt(t1)) %>
2.<%= (char) (64 + Integer.parseInt(t2)) %>
3.<%= (char) (64 + Integer.parseInt(t3)) %>
<br>
<%="正確題數:"+a %>
</body>
</html>
執行效果
透過form中的action進行頁面的跳轉和資料的傳遞