日期:2014-05-17  浏览次数:20680 次

新人求解??? 报错。。。 请高手指点,
<%@ page language="java" pageEncoding="utf8"%>
<%@ page import="java.io.*"%>
<%@ page import="java.math.*"%>
<%@ page import="java.util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'MyJsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%! BigInteger count = null;%>
<% public BigInteger load(File file){
  //BigInteger count = null;
  try{
  if(file.exists()){
  Scanner scan = new Scanner(new FileInputStream(file));
  if(scan.hasNext()){
cout = new BigInteger(scan.next());
}
scan.close();
  }else{
  count = new BigInteger("0");
save(file,cout);
  }
  }catch(Exception e){
  e.printStackTrace();
  }
  return count;
}
 public void save(File file,BigInteger count){
  try{
PrintStream ps = null;
ps = new PrintStream(new FileOutputStream(file));
ps.println(count);
ps.close();
}catch(Exception e){
e.printStackTrace();
}
  
 }  
 %>
<%
  String fileName = this.getServletContext().getRealPath("/")+
"count.txt";
File file = new File(fileName);
if(session.isNew()){
 
synchronized(this){
count=load(file);
count= count.add(new BigInteger("1"));
save(file,count);
}
} %>
<h2>
您是第<%=count==null?0:count%>访客
</h2>
</body>
</html>


------解决方案--------------------
..........
if(file.exists()){
Scanner scan = new Scanner(new FileInputStream(file));
if(scan.hasNext()){
cout = new BigInteger(scan.next());}
scan.close();
}else{
count = new BigInteger("0");
save(file,cout);
}
............
上面两处红色的地方那个变量在哪定义的,cout应该是count吧