为什么jsp文件能正常运行,但不能用Bean?

04-11-01 xiefod
我碰到这样一个问题,找不到Bean 对象,哪位能帮忙指点下,谢谢!

jsp,java src与class文件在目录D:\myJSP\jsp\count下面

另外还有一文本文件lyfcount.txt也放在D:\myJSP\jsp\count下面

原文件如下:

//test.jsp文件

<%@ page contentType="text/html;charset=gb2312"%>

<%@ page language="java" import="count.*" %>

<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="counter" class="count.counter" scope="request">

</jsp:useBean>

<%

//调用counter对象的ReadFile方法来读取文件lyfcount.txt中的计数

String cont=counter.ReadFile("/lyfcount.txt");

//调用counter对象的ReadFile方法来将计数器加一后写入到文件lyfcount.txt中

counter.WriteFile("/lyfcount.txt",cont);%>

您是第<font color="red"><%=cont%></font>位访问者

</BODY>

</HTML>

java src 如下:

//counter.java 读写文件的一个bean

package count;

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());

}

}

}

在IE中运行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: 13 in the jsp file: /jsp/count/test.jsp

Generated servlet error:

[javac] Compiling 1 source file

C:\Tomcat4\work\Standalone\localhost\myJSP\jsp\count\test_jsp.java:7: package count does not exist

import count.*;

^

C:\Tomcat4\work\Standalone\localhost\myJSP\jsp\count\test_jsp.java:54: cannot resolve symbol

symbol : class counter

location: package count

count.counter counter = null;

^

An error occurred at line: 13 in the jsp file: /jsp/count/test.jsp

Generated servlet error:

C:\Tomcat4\work\Standalone\localhost\myJSP\jsp\count\test_jsp.java:56: cannot resolve symbol

symbol : class counter

location: package count

counter = (count.counter) pageContext.getAttribute("counter", PageContext.REQUEST_SCOPE);

^

An error occurred at line: 13 in the jsp file: /jsp/count/test.jsp

Generated servlet error:

C:\Tomcat4\work\Standalone\localhost\myJSP\jsp\count\test_jsp.java:59: cannot resolve symbol

symbol : class counter

location: package count

counter = (count.counter) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "count.counter");

^

4 errors

xiefod
2004-11-01 17:04
怪怪,贴上去的jsp源文件没有显示出来,注释掉也不行。

贴上来

xiefod74P012A3l5.txt

xiefod
2004-11-01 17:08
还是看不到 :(

xiefod
2004-11-01 17:11

<p class="indent">//test.jsp文件<p class="indent"><%@ page contentType="text/html;charset=gb2312"%><p class="indent"><%@ page language="java" import="count.*" %><p class="indent"><HTML><p class="indent"><HEAD><p class="indent"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><p class="indent"><META NAME="GENERATOR" CONTENT="Oracle JDeveloper"><p class="indent"><TITLE><p class="indent">计数器演示程序<p class="indent"></TITLE><p class="indent"></HEAD><p class="indent"><BODY><p class="indent"><!--创建并调用bean(counter)--><p class="indent"><jsp:useBean id="counter" class="count.counter" scope="request"><p class="indent"></jsp:useBean><p class="indent"><%<p class="indent">//调用counter对象的ReadFile方法来读取文件lyfcount.txt中的计数<p class="indent">String cont=counter.ReadFile("/lyfcount.txt");<p class="indent">//调用counter对象的ReadFile方法来将计数器加一后写入到文件lyfcount.txt中<p class="indent">counter.WriteFile("/lyfcount.txt",cont);%><p class="indent">您是第<font color="red"><%=cont%></font>位访问者<p class="indent"></BODY><p class="indent"></HTML><p class="i

xiefod
2004-11-02 11:49
怎么没人帮帮忙呢?

这两个文件应该如何放才能跑起来呢?

我用的Web Server是Tomcat.

猜你喜欢
2Go 1 2 下一页