<%@ page import="java.util.*"%>
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%
int num;
if(application.getAttribute("num")==null)
{
application.setAttribute("num","1");
}
else{
num=Integer.parseInt((String)application.getAttribute("num"));//mark
num++;
application.setAttribute("num",Integer.toString(num));
out.println(application.getAttribute("num").getClass().getName());
out.println((String)application.getAttribute("num").getClass().getName());
}
%>
这个页面已经被浏览了<%=(String)application.getAttribute("num")%>次
------------------------------输出----------------------------------
[img]http://dl2.iteye.com/upload/attachment/0096/1262/94484d69-36dc-3535-bac7-40bbd90d8b04.jpg[/img]
既然application.getAttribute("num")返回类型是String,那么为什么把//mark处的代码改为num=Integer.parseInt(application.getAttribute("num");则会提示:The method parseInt(String) in the type Integer is not applicable for the arguments (Object)?