回 帖 发 新 帖 刷新版面

主题:怎样运行java文件?

我在教程上面看到一个例子,有一个ReadFile.java文件,有一个read.jsp用javabean来调用,运行的时候,有这样一个错误:
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: /read.jsp

Generated servlet error:
    [javac] Compiling 1 source file

D:\Tomcat 4.1\work\Standalone\localhost\jsp\read_jsp.java:52: package ch8 does not exist
      ch8.ReadFile reader = null;
         ^



An error occurred at line: 10 in the jsp file: /read.jsp

Generated servlet error:
D:\Tomcat 4.1\work\Standalone\localhost\jsp\read_jsp.java:54: package ch8 does not exist
        reader = (ch8.ReadFile) pageContext.getAttribute("reader", PageContext.REQUEST_SCOPE);
                     ^



An error occurred at line: 10 in the jsp file: /read.jsp

Generated servlet error:
D:\Tomcat 4.1\work\Standalone\localhost\jsp\read_jsp.java:57: package ch8 does not exist
            reader = (ch8.ReadFile) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "ch8.ReadFile");
                         ^
3 errors

,[color=FF0000]请问应该怎样正确调用.java文件呢?
.java文件我已经编译了,在当前目录下面生成了一个ch8的文件夹,里面有ReadFile.class一个文件;
read.jsp的内容如下:[/color]<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JSP读取文件</title>
</head>

<body>
<%--调用javabean--%>
<jsp:useBean id="reader" class="ch8.ReadFile" scope="request">
<jsp:setProperty name="reader" property="path" value="e:\\jsp\\datafile.txt" />
</jsp:useBean>
<h3>文件内容</h3>
<p>
<% int count=0; %>
<% while (reader.nextRecord()!=-1){ %>
<% count++; %>
<b>第<%= count %>行;</b>
<% out.print(reader.returnRecord()); %><br />
<% } %>
</p>
</body>
</html>

回复列表 (共12个回复)

沙发

小弟昨天也运行了一个jsp+javaBean的程序,先也有错误,结果改后可以了,不如你把程序发到我的邮箱,我改好后给你
gaoqing0000@163.com

板凳

好的,非常感谢!待会儿发给你,帮我看看

3 楼

已经发过去了,查收一下请

4 楼

其他高手,有没有知道怎么解决的?

5 楼

小弟看了一下,没有错呀,运行正确呀.

6 楼

你是怎么运行的?怎么在我这里一直有错误?运行结果是什么?

7 楼

文件里面有什么,就显示什么,你要建一个文件才行呀,

8 楼

[quote]文件里面有什么,就显示什么,你要建一个文件才行呀,
[/quote]
建一个文件是什么意思?

9 楼

做过关于文件的程序没有?, 要有这个文件才行呀,没有这个文件,它就会说有错误,比如"file not found"

10 楼

当然有文件了

我来回复

您尚未登录,请登录后再回复。点此登录或注册