主题:关于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下面的文件夹里面时,会发生异常)
==========================================
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下面的文件夹里面时,会发生异常)