为什么访问数会是0呢?
在Java中声明的Count初始值为1啊
Counter.jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'Counter.jsp' starting page</title>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<jsp:useBean id="personCounter" class="property.Counter" scope="session"/>
<jsp:useBean id="totalCounter" class="property.Counter" scope="application"/>
<jsp:setProperty name="personCounter" property="count" />
<div align="center"><label>访问次数统计:</label>
<form align="center">
<table border="0">
<tr><td>
个人访问次数:<jsp:getProperty name="personCounter" property="count"/>
</td></tr>
<tr><td>
总的访问次数:<jsp:getProperty name="totalCounter" property="count"/> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
Counter.java代码如下:
package property;
public class Counter {
private int count=1;
public void setCount(int count){
this.count=count;
}
public int getCount(){
return ++count;
}
}
------解决思路----------------------
经测试,不为0 啊。
测试环境,java8+tomcat8+eclipse