请帮看一下这个jsp那儿出错,在线等待.

bigtree0906 2006-08-01 09:03:24
SimpleCount.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Simple Counter</title>
</head>
<body gbcolor=#ffffff>
<%@ page import="java.io.*"%>
<%
BufferedReader file;
String countFile = "count.txt";
try
{
file = new BufferedReader(new FileReader(countFile));
}
catch(IOException e)
{
out.println(e.getMessage());
}

String readstr=null;
int writestr=1;
try
{
readstr = file.readLine();
}
catch(IOException e)
{
System.out.println("读取数据错误.");
}

if (readstr == null) readstr ="没有任何记录";
else
{
writestr = Integer.parseInt(readstr) + 1;
}

try
{
PrintWriter pw;
pw = new PrintWriter(new FileOutputStream(countFile));
pw.println(writestr);
pw.close();
}
catch (IOException e)
{
out.println(e.getMessage());
}
%>
<p align="center">
--><h1>文字模式访问计数器: </h1>
<h3>你是本网页的第
<font color="FF0000" size="7">
<%=readstr%>
</font>名访客
</h3>
</p>
</body>
</html>



报的错如下:


HTTP Status 500 -

--------------------------------------------------------------------------------

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: 10 in the jsp file: /SimpleCount.jsp

Generated servlet error:
[javac] Compiling 1 source file

D:\software\Tomcat 5.0\webapps\test\work\org\apache\jsp\SimpleCount_jsp.java:58: variable file might not have been initialized
readstr = file.readLine();
^
1 error


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:552)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.16
...全文
162 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigtree0906 2006-08-05
  • 打赏
  • 举报
回复
我用的是Eclipse3.11+Tomcat5.0.16.由程序自主产生count.txt文件,居然是在\eclipse-SDK-3.1.1-win32\eclipse的目录下,想不明白其所以原.
谢谢各位,问题是解决了,但还想问一下原因.
kevinliuu 2006-08-04
  • 打赏
  • 举报
回复
String countFile = "count.txt"; //这种定义方式,需要把文件放在Tomcat\bin目录下

一般配置文件或需要操作读写的文件放在应用目录的\WEB-INF\下
feigme 2006-08-04
  • 打赏
  • 举报
回复
String nameOfTextFile = "e:\\count.txt";

//读取
file = new BufferedReader(new FileReader(nameOfTextFile));

试试
bigtree0906 2006-08-04
  • 打赏
  • 举报
回复
谢谢各位.是的,这个是因为"count.txt"找不到.
象如此的情况(Apache Tomcat/5.0.16)此文件应该放在哪个目录下,或怎样指定目录路径?
sheep219 2006-08-01
  • 打赏
  • 举报
回复
两个地方的问题:
<%@ page import="java.io.*"%>
<%
BufferedReader file = null;
//这里要初始化一下

try
{
if(file!=null)
//这里要判断是否为空
readstr = file.readLine();
}
catch(IOException e)
{
System.out.println("读取数据错误.");
}
idlx 2006-08-01
  • 打赏
  • 举报
回复
BufferedReader file;
改为
BufferedReader file = null;
BabyGirl8210 2006-08-01
  • 打赏
  • 举报
回复
BufferedReader file;
file没有被初始化
blackwolf1983 2006-08-01
  • 打赏
  • 举报
回复
初始化试试啊!我只能想到这个.
bigtree0906 2006-08-01
  • 打赏
  • 举报
回复
没人,自己顶一下.

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧