怎样调用.java文件?

itzhiren 2006-02-23 02:17:22
现在有一个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

,请问应该怎样正确调用.java文件呢?
...全文
430 点赞 收藏 17
写回复
17 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
itzhiren 2006-03-03
总是提示类没有找到,到底应该放在那个目录下面呢?
回复
itzhiren 2006-03-03
同样的javabean调用,我已经成功了一个了,可是这个不知道为什么一直没有成功。
回复
itzhiren 2006-03-03
哦,我自己已经建立了,并且把ch8\ReadFile.class放在了classes下面,不知道我拷贝的路径对不对?我再详细说一下吧。
有两个文件
第一个:E:\jsp\WEB-INF\classes\ch8\ReadFile.class
第二个:E:\jsp\Read.jsp
第二个文件内容如下:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<html>
<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\\datefile.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>
,运行http://localhost:8080/jsp/Read.jsp,有错误信息:
HTTP Status 500 -

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

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

请问这怎么解决?
回复
songbin3711 2006-03-03
classes文件夹需要你自己建立
回复
itzhiren 2006-02-24
\Tomcat\webapps\ROOT\classes

/////////////////////////////////////////
没有这个目录呀
回复
linilg 2006-02-24
把\Tomcat\webapps\ROOT\classes文件拷贝到你的虚拟目录下,重启tomcat
回复
itzhiren 2006-02-24
我就是运行的jsp文件呀,就出来以上的错误了,是不是java文件和class文件的路径还是没有放对呀?
回复
linilg 2006-02-24
java文件和class可以不用管,只管运行jsp就行。
回复
itzhiren 2006-02-24
我把classes文件夹拷贝到e:\jsp下面,然后运行http://localhost:8080/jsp/read.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
at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:454)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:102)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:147)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


root cause

java.lang.ClassNotFoundException: org.apache.jsp.Read_jsp
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:161)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:83)
at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:451)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:102)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:147)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)



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

Apache Tomcat/4.1.31
回复
itzhiren 2006-02-24
是拷贝classes还是只拷贝classes下面的文件?
回复
linilg 2006-02-24
你的.jsp文件按你的虚拟目录运行正确,
但你的.java文件和.class 文件在\WEB-INF\classes下存在,
把这个目录全部复制到你的虚拟目录就行。
回复
itzhiren 2006-02-23
我把ch8整个文件夹和read.jsp都拷贝到了D:\Tomcat 4.1\webapps\ROOT\WEB-INF下面,我设置虚拟目录是e:\jsp,访问地址:http://127.0.0.1:8080/jsp/Read.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
at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:454)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:102)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:147)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


root cause

java.lang.ClassNotFoundException: org.apache.jsp.Read_jsp
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:161)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:83)
at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:451)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:102)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:147)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)



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

Apache Tomcat/4.1.31
回复
wsk_228 2006-02-23
WEB-INF\classes\ch8\ReadFile.class
read.jsp
回复
scottwhb 2006-02-23
把ch8整个文件夹拷贝过去吗?发布目录是哪一个?如果都拷贝过去了,那访问的地址还应该是原来的地址吗?
------------------------------------------------
整个都拷过去,发布目录是WEB-INF\classes,访问的还是原来的地址.
回复
itzhiren 2006-02-23
把ch8整个文件夹拷贝过去吗?发布目录是哪一个?如果都拷贝过去了,那访问的地址还应该是原来的地址吗?
回复
infowain 2006-02-23
你要ch8的文件夹和里面的ReadFile.class文件复制到你的发布目录的WEB-INF\classes目录里面
回复
itzhiren 2006-02-23
.java文件我已经编译了,在当前目录下面生成了一个ch8的文件夹,里面有ReadFile.class一个文件;
read.jsp的内容如下:
<%@ 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>
回复
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-02-23 02:17
社区公告
暂无公告