JSP中的全局变量和局部变量
AccessCounts.jsp
<html>
<head>
<title>JSP Declaration</title>
</head>
<body>
<%!
// 全局变量
int accessCount = 0;
%>
<%
// 局部变量
int accessCount2 = 0;
%>
<h2>AccessCount:
<br>Overall Variable:<%= ++accessCount %>
<br>Local Variable:<%= ++accessCount2 %>
</h2>
</body>
</html>
测试结果:访问同一页面,每刷新一次,accessCount增1,accessCount2不变(每次出现一个新的局部变量)。
AccessCounts.jsp
<html>
<head>
<title>JSP Declaration</title>
</head>
<body>
<%!
// 全局变量
int accessCount = 0;
%>
<%
// 局部变量
int accessCount2 = 0;
%>
<h2>AccessCount:
<br>Overall Variable:<%= ++accessCount %>
<br>Local Variable:<%= ++accessCount2 %>
</h2>
</body>
</html>
测试结果:访问同一页面,每刷新一次,accessCount增1,accessCount2不变(每次出现一个新的局部变量)。