解答例 - 実習課題3 - 2.JSPの基本2
(実習課題3)
以下のJSPページを作成しなさい。
- そのページに何回訪れたかを表示する。
- 訪れた回数の管理はセッションで行う事。
解答例
<!-- count.jsp -->
<!-- TECHSCORE Java JSP 2章 実習課題3 -->
<!-- Copyright (c) 2004 Four-Dimensional Data, Inc. -->
<%@page contentType="text/html; charset=Windows-31J" session="true" %>
<html>
<head><title>JSP 2章 実習課題 3</title></head>
<body>
<h3>JSP 2章 実習課題 3</h3>
<%
int i;
if(session.getAttribute("count")!=null){
i = ((Integer)session.getAttribute("count")).intValue();
}else{
i = 0;
}
i++;
%>
Count: <%= i %>
<%
session.setAttribute("count", new Integer(i));
%>
</body>
</html>

