新 out.println(new Date().toLocaleString()); //获得当前时间 %>
</body> </html>
3.答案:
<%@ page contentType="text/html;charset=GB2312" %> <HTML> <BODY>
<%! int number=0;
synchronized void countPeople()
{
number++; } %> <%
if(session.isNew()) {
countPeople();
String str=String.valueOf(number); session.setAttribute("count",str); } %>
<P>您是第<%=(String)session.getAttribute("count")%>个访问本站的人。
<BODY>
<HTML>
4.答案:
<%@ page contentType="text/html; charset=GB2312" import="java.util.Date"%> <html> <head><title>Application 计数器</title></head>
<body> <center>
<font size = 5 color = blue>Application 计数器</font>
</center> <hr>
<%
String strNum = (String)application.getAttribute("num");
int num = 0;
//检查是否 Num 变量是否可取得 if(strNum != null)
num = Integer.parseInt(strNum) + 1; //将取得的值增加 1
application.setAttribute("num", String.valueOf(num)); //起始 Num 变量值 %>
访问次数为:
<font color = red><%= num %></font><br> 一次刷
</body> </html>