奇怪的问题,第一次执行一定有错,错误提示如下。刷新后能正常运行,但偶尔还会出现错误,大概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>
本人第一次用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>
解决方案 »
- Hibernate关于对数据的封装
- Struts+Spring+hibernate求救!!急急急!!!
- 求jsp网站开发的实例源码!!!!
- 表格的行中嵌入树型如何实现呢?(急!!)
- 紧急求助,在struts中我如何自己生成一个FormFile对象
- form表单中select的onchange事件无反应
- ajax发送json到后台,servlet如何解析成一个对象
- 探讨大数据量的分页实现
- 谁会在weblogic6.1中配置sevlets????来帮帮我好吗??????急啊!!!!!!!!!!!
- 怎么验证程序运行在spring事务中?
- 各位前辈,请救命哦《关于select option控件如何按ID号排序问题》
- javascript向STURTS表单传值的问题
=>
public int GetClicks()