奇怪的问题,第一次执行一定有错,错误提示如下。刷新后能正常运行,但偶尔还会出现错误,大概50次左右出现一次,不定。
本人第一次用JSP,请各路高人指教。光配置环境就花了大半个小时,还不知道环境对不对,现在先用netBeans IDE 5.0试着。另外,我是为了改别人的一个程序,有一个网站的计数器不正常,有时好用,有时乱跳,程序我又看不懂,只好自己尝试做一个了;但不知道各位高手有没有碰到类似的问题?
type Exception report
message 
description The server encountered an internal error () that prevented it from fulfilling this request.
exception 
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 8 in the jsp file: /LKCount.jsp
Generated servlet error:
C:\Documents and Settings\Administrator\.netbeans\5.0\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\WebApplication1\org\apache\jsp\LKCount_jsp.java:51: ';' expected
int GetClicks()
             ^
1 error源代码:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>JustTest</title>
</head>
<body>
<%
int GetClicks()
{
    String readStr = null;    String temp = request.getParameter("entryID");
    int itemp=0;
    try{itemp = Integer.parseInt(temp);}catch (Exception e) {itemp = 0;}    //转换传入的参数值,出错则使用非0值;    String FileName = "Count" + itemp + ".txt";    String path = request.getRealPath("/LKCount");
    File f = new File(path,FileName);    if(f.exists()==false){//检查Count****.txt是否存在,不存在则创建一个
        try
        { 
            f.createNewFile();//在当前目录下建立一个名为Count****.txt的文件,并写0至该文件;
            
            PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile)); 
            pw.println("0"); 
            pw.close();
        } 
        catch(IOException e){ return 0;} 
    }
    //============================判断文件是否存在,如不存在,则新建一个文件。    String nameOfTextFile = path + "\\" + FileName; 
    BufferedReader tempfile; //BufferedReader对象,用于读取文件数据
    tempfile = new BufferedReader(new FileReader(nameOfTextFile)); 
    readStr = tempfile.readLine();  //读取文件中的计数值
    tempfile.close();    int writeStr=0;
    if (readStr == null)
    {
      readStr = "没有任何记录"; 
    }else{
        writeStr = Integer.parseInt(readStr)+1;
    }
    //=======================================================读取文件,判断是否为空    if (f.exists())
    {
        try
        { 
            PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile)); 
            pw.println(writeStr); 
            pw.close();
        } 
        catch(IOException e){ }
    }
    
    return writeStr;
}
%><%= GetClicks() %>
</body>
</html>