回 帖 发 新 帖 刷新版面

主题:关于javaBean在jsp中使用时的设置问题

我的tomcat4.1匙安装在目录D:\ApacheGroup\Tomcat4.1\下面,其他的设置都是正确的(已做过测试),但是在JSP中应用javaBean时遇到N多问题,下面是我的一个jsp页面文件和一个java源代码以及它们所存放的路径:

==========================================
JSP文件:
路径:D:\ApacheGroup\Tomcat4.1\webapps\ROOT\myjsp\HelloWorld.jsp

源代码:

<%@page import="test.HelloWorld"%>
<jsp:useBean id="Helloworld" class="test.HelloWorld" scope="application" type="test.HelloWorld"/>
<jsp:getProperty name="Helloworld" property="name"/>


java源代码:
路径:D:\ApacheGroup\Tomcat4.1\webapps\ROOT\WEB-INF\classes\test\HelloWorld.java

源代码:

package test;

public class HelloWorld {
public String name = "My first bean";

public String getName() {
return name;
}
}

==========================================

在IE浏览器中的地址栏上面输入 http://localhost:8080/myjsp/HelloWorld.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.HelloWorld_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
==========================================

然而,我把HelloWorld.jsp文件,在不经过任何修改的前提下,拷贝了一份到目录 D:\ApacheGroup\Tomcat4.1\webapps\ROOT\ 下面
然后,在IE浏览器中的地址栏上面输入 http://localhost:8080/HelloWorld.jsp 时,页面则正常的输出相关信息。

后来又在 D:\ApacheGroup\Tomcat4.1\webapps\examples目录下面做类似的实验:
将 D:\ApacheGroup\Tomcat4.1\webapps\ROOT\WEB-INF\classes\test 中的 HelloWorld.java
拷贝到 D:\ApacheGroup\Tomcat4.1\webapps\examples\WEB-INF\classes\test 下面

然后将前面的 HelloWorld.jsp 拷贝到 D:\ApacheGroup\Tomcat4.1\webapps\examples\myjsp 和
D:\ApacheGroup\Tomcat4.1\webapps\examples\ 下面
然后在IE中输入 http://localhost:8080/examples/HelloWorld.jsp 和
http://localhost:8080/examples/myjsp/HelloWorld.jsp , 均可以输出的正确的结果。

问题是:
希望高人指点小生一下:为什么在exmaples目录下面,HelloWorld.jsp就可以随便在什么字目录里面都可以得到正确的结果,而在ROOT目录下面,就不能放到ROOT的子目录下面呢?(如前面所示,HelloWorld.jsp放在ROOT下面的文件夹里面时,会发生异常)

回复列表 (共9个回复)

沙发

你试试看把HelloWorld.jsp从 ROOT/myjsp/ 移到 ROOT/ 下也许就行了 :=)

板凳

package test;

public class HelloWorld {
public String name = "My first bean";

public String getName() {
return name;
}

test放的位置错了

3 楼

同我问题一样
test包应该放在哪里呢?望高手赐教!!!!!

4 楼

放在WEB-INF/classes的目录下边

5 楼

你的test写的不对
还应该有不带参数的构造函数和setName()这个方法啊
如果还不行的话,你改改<jsp:useBean id="Helloworld" class="test.HelloWorld" scope="application" type="test.HelloWorld"/>中的class="test.HelloWorld“的路径

6 楼

Jsp文件应该直接放在ROOT目录下,还有就是你应该在Jsp文件中为Java中的类实例化一个对象

7 楼

出售:中游 联众 QQ 边锋 茶苑 游戏辅助软件
客服QQ:404481628 网站地址:http://www.zmbw.com/suoha
游戏区               软件名称                零售价格
边锋游戏 边锋港式五张(梭哈)看牌器2.36          128.00  
  边锋三跟看牌器1.03                           128.00  
  边锋刷分器1.63                               128.00  
  边锋麻将看牌器2.03                           118.00  
  边锋四国看牌器1.09                           118.00  
  边锋假银制做器2.34                           128.00  
  边锋双扣三扣一看牌器2.1                      118.00   
  边锋十三水看牌器1.11                         118.00   
  边锋断线器1.08                               118.00   
  边锋反作弊器1.26                             118.00   
  边锋三IP代理服务器1.2                        118.00   
-----------------------------------------------------
联众游戏 联众港式五张看牌器2.42 查看截图       128.00  
  联众赢三张看牌器1.03                         128.00  
  联众碰运气作弊器1.04                         128.00  
  联众幸运21看牌器1.06                         128.00  
  联众四国军旗看牌器1.01                       128.00  
  联众刷分器1.03                               128.00   
  联众升级看牌器1.25                           118.00   
  联众假财富制做器2.1                          128.00  
  联众保皇看牌器1.27                           118.00  
  联众双扣三打一看牌器1.3                      118.00   
  联众斗地主看牌器1.3                          118.00  
  联众断线器1.04                               118.00   
  联众反作弊器2.09                             118.00   
-----------------------------------------------------
中国游戏在线 中游五张牌梭哈看牌器1.52 查看截图 128.00  
  中游三跟看牌器1.22                           128.00  
  中游刷分器1.05                               128.00  
  中游金币麻将看牌器1.05                       118.00  
  中游军棋看牌器1.19                           118.00  
  中游假币制做器1.28                           128.00  
  中游锄大地看牌器1.5                          118.00  
  中游21点看牌器1.26                           118.00  
  中游斗地主看牌器1.8                          118.00  
  中游断线器2.22                               118.00   
  中游反作弊器2.04                             118.00   
-----------------------------------------------------
远航游戏 远航五张牌看牌器1.01 查看截图         128.00  
  远航飘三叶看牌器1.26                         128.00  
  远航保皇看牌器1.2                            118.00  
  远航挖坑看牌器1.06                           118.00  
  远航假金币制做器1.35                         128.00  
  远航断线器1.09                               118.00   
  远航反作弊器1.01                             118.00   
-----------------------------------------------------

客服QQ:404481628 网站地址:http://www.zmbw.com/suoha

8 楼

HelloWorld.java经过编译后自动产生的HelloWorld.class文件有没有带着一起copy?

9 楼

需要设置环境变量
JAVA_HOME  ....(安装的文件夹 eg:  C:\java1.4.2)
TOMCAT_HOME  .....(文件夹 eg: C:\tomcat)

我来回复

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