日期:2014-05-18  浏览次数:20722 次

大家帮我看下这段application的代码哪里错了,在线等。
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<title>使用application对象实现的网页计数器</title>
</head>
<body>
<center>
<h5>使用application对象实现的网页计数器</h5>
<hr />
<%
  request.setCharacterEncoding("gb2312");
request.getSession(true);
//通过getAttribute方法获取数据并赋给变量counter
String counter=(String)application.getAttribute("counter");
//判断application对象中用于存储数据值是否为空
if(counter!=""){
//如果不为,将数据从字符串转换为整型
int int_counter=Integer.parseInt(counter);z
//计算器值增1
int_counter+=1;
//将加1后的数值再转化为字符类型进行存储
String str_counter=String.valueOf(int_counter);
application.setAttribute("counter",str_counter);
}
//如果为空,则将数值1保存到application对象名称counter中
else
{
application.setAttribute("counter","1");
}
out.print("你是访问本网站的第"+counter+"位网友!");
%>
</center>
</body>
</html>


------解决方案--------------------
应该是 if(counter!=null)