0
我想要統計每個用戶進入網站的次數,但我的問題是即使我更改了用戶名,命中次數也不會重新啓動。另外,一旦我重新加載網頁,用戶的名字就變成「null」。JSP用戶點擊計數器
<HTML>
<BODY>
<FORM METHOD=POST ACTION="SaveName.jsp">
Who are You ? <INPUT TYPE=TEXT NAME=username SIZE=20>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
<%@ page import="java.io.*,java.util.*" %>
<html>
<head>
<title>Applcation object in JSP</title>
</head>
<body>
<%
String name = request.getParameter("username");
session.setAttribute("theName", name);
Integer hitsCount =
(Integer)application.getAttribute("hitCounter");
if(hitsCount ==null || hitsCount == 0){
/* First visit */
out.println("Welcome to my website! ");
hitsCount = 1;
}else{
/* return visit */
out.println("Welcome back to my website!");
hitsCount += 1;
}
application.setAttribute("hitCounter", hitsCount);
%>
<%= session.getAttribute("theName") %>
<br>Total number of visits: <%= hitsCount%></br>
</body>
</html>
有一些困惑,你想做什麼?你想爲每個用戶點擊數嗎? – 2012-04-09 04:39:47
是的,我希望每個用戶的點擊數 – toky 2012-04-10 18:31:57