jsp新手,关于计数器问题的,急问,高分求助!!!!!

interstar 2003-05-04 04:30:20
刚刚接触jsp,按照网上的计数器代码编写jsp,但总是运行错误,求高手帮助!
我的jsp配置是jdk1.4+tomcat4.1,环境变量的设置如下:CLASSPATH=C:\jdk1.4\lib\tools.jar;C:\jdk1.4\lib\dt.jar;C:\jdk1.4\bin PATH=C:\jdk1.4\bin;C:\jdk1.4,IE中敲入:http://127.0.0.1,可以正常出现tomcat的画面,说明配置没有问题,计数器代码如下:
//counter.java
//读写文件的一个bean
import java.io.*;
public class counter extends Object {
private String currentRecord = null;//保存文本的变量
private BufferedReader file; //BufferedReader对象,用于读取文件数据
private String path;//文件完整路径名
public counter() {
}
//ReadFile方法用来读取文件filePath中的数据,并返回这个数据
public String ReadFile(String filePath) throws FileNotFoundException
{
path = filePath;
//创建新的BufferedReader对象
file = new BufferedReader(new FileReader(path));
String returnStr =null;
try
{
//读取一行数据并保存到currentRecord变量中
currentRecord = file.readLine();
}
catch (IOException e)
{//错误处理
System.out.println("读取数据错误.");
}
if (currentRecord == null)
//如果文件为空
returnStr = "没有任何记录";
else
{//文件不为空
returnStr =currentRecord;
}
//返回读取文件的数据
return returnStr;
}
//ReadFile方法用来将数据counter+1后写入到文本文件filePath中
//以实现计数增长的功能
public void WriteFile(String filePath,String counter) throws FileNotFoundException
{
path = filePath;
//将counter转换为int类型并加一
int Writestr = Integer.parseInt(counter)+1;
try {
//创建PrintWriter对象,用于写入数据到文件中
PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
//用文本格式打印整数Writestr
pw.println(Writestr);
//清除PrintWriter对象
pw.close();
} catch(IOException e) {
//错误处理
System.out.println("写入文件错误"+e.getMessage());
}
}
}
编译可以通过,生成counter.class文件

//test.jsp文件
<%@ page contentType="text/html;charset=gb2312"%>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
<TITLE>
计数器演示程序
</TITLE>
</HEAD>
<BODY>
<!--创建并调用bean(counter)-->
<jsp:useBean id="mycounter" class="counter" scope="request">
</jsp:useBean>
<%
//调用mycounter对象的ReadFile方法来读取文件lyfcount.txt中的计数
String cont=mycounter.ReadFile("/lyfcount.txt");
//调用mycounter对象的ReadFile方法来将计数器加一后写入到文件lyfcount.txt中
mycounter.WriteFile("/lyfcount.txt",cont);
%>
您是第<font color="red"><%=cont%></font>位访问者
</BODY>
</HTML>
jdk的安装目录为:C:\jdk1.4 tomcat的安装目录为:C:\Tomcat 4.1
counter.java和counter.class文件放于C:\Tomcat 4.1\webapps\MyJSPApp\WEB-INF\classes文件夹下
test.jsp文件放于C:\Tomcat 4.1\webapps\MyJSPApp\counter文件夹下
在IE中敲入:http://127.0.0.1/MyJSPApp/counter/test.jsp
出现错误提示: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: 22 in the jsp file: /counter/test.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Tomcat 4.1\work\Standalone\localhost\MyJSPApp\counter\test_jsp.java:51: cannot resolve symbol
symbol : class counter
location: class org.apache.jsp.test_jsp
counter mycounter = null;
^
An error occurred at line: 22 in the jsp file: /counter/test.jsp
Generated servlet error:
C:\Tomcat 4.1\work\Standalone\localhost\MyJSPApp\counter\test_jsp.java:53: cannot resolve symbol
symbol : class counter
location: class org.apache.jsp.test_jsp
mycounter = (counter) pageContext.getAttribute("mycounter", PageContext.REQUEST_SCOPE);
^
An error occurred at line: 22 in the jsp file: /counter/test.jsp
Generated servlet error:
C:\Tomcat 4.1\work\Standalone\localhost\MyJSPApp\counter\test_jsp.java:56: cannot resolve symbol
symbol : class counter
location: class org.apache.jsp.test_jsp
mycounter = (counter) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "counter");
^
3 errors
请高手给予帮助,如果可行的话,立即给分(100),万分感谢!

...全文
37 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
getwill 2003-05-04
  • 打赏
  • 举报
回复
jdk1.4要包!如果用jdk1.3就不会出现问题,同时要将classpath 要加在tomcat上

81,091

社区成员

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

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