JSPAdvertisementforwardアクション
書式
<jsp:forward page="転送するページ" />このアクションが実行されると、指定先ページへ転送される。 includeアクションの利用
メイン
<%@ page contentType="text/html; charset=Shift_JIS" %>
<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS">
<html lang="ja">
<head>
<title>test</title>
</head>
<body>
<%
String next = request.getParameter("next");
if(next != null){
if(next.equals("1")){
%>
<jsp:forward page="good.jsp" />
<%
}else if(next.equals("2")){
%>
<jsp:forward page="bad.jsp" />
<%
}
}
%>
<h1>問題</h1>
<p>
1 + 1 = ?<br>
<br>
[1] <a href="./forward.jsp?next=1">1</a><br>
[2] <a href="./forward.jsp?next=2">2</a>
</p>
</body>
</html>
good.jsp
<%@ page contentType="text/html; charset=Shift_JIS" %> <meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS"> <html lang="ja"> <head> <title>正解</title> </head> <body> <h1>正解</h1> <p> <em>○ 1 + 1 = 2<em><br> × 1 + 1 = 1<br> </p> </body> </html>bad.jsp <%@ page contentType="text/html; charset=Shift_JIS" %> <meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS"> <html lang="ja"> <head> <title>不正解</title> </head> <body> <h1>不正解</h1> <p> ○ 1 + 1 = 2<br> <em>× 1 + 1 = 1<em><br> </p> </body> </html> |