当前位置: 代码迷 >> Java Web开发 >> 计数器问题
  详细解决方案

计数器问题

热度:309   发布时间:2007-11-17 11:06:43.0
计数器问题

不知道怎么改这个程序,大虾帮忙
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!
synchronized void countPeople()
{
ServletContext application =getServletContext();
Integer number= (Integer)application.getAttribute("Count");


if (number==null){
number=new Integer(1);
application.setAttribute("Count",number);
}
else {
number= new Integer(number.intValue()+1);
application.setAttribute("Count",number);
}

}
%>
<%! Integer yourNumber= new Integer(0);
if( session.isNew()){
countPeople();
yourNumber = (Integer)application.getAttribute("Count");

}
%>
<P><P>欢迎你:你是第
<% =yourNumber %>
位来客
</body>
</html>

搜索更多相关主题的帖子: 计数器  

----------------解决方案--------------------------------------------------------

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JSP Page</title>
</head>
<body>
<%
ServletContext app =getServletContext();
Integer number= (Integer)app.getAttribute("Count");
if(number==null){
number=new Integer(1);
application.setAttribute("Count",number);
}
else
{
number= new Integer(number.intValue()+1);
application.setAttribute("Count",number);
}
%>
<P><P>欢迎你:你是第<%=((Integer)app.getAttribute("Count")).intValue()%> 位来客
</body>
</html>

[此贴子已经被作者于2007-11-17 11:18:12编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案