当前位置: 技术问答>java相关
配好 JDK+TOMCAT 环境后,就能直接用JAVABEAN吗?
来源: 互联网 发布时间:2015-10-15
本文导语: 配好 JDK+TOMCAT 环境后,就能用JAVABEAN吗? 我建好TOMCAT后(可以正常运行JSP程序),试图用一下JAVABEAN,程序特别简单,还是出错。哪位大哥能告诉我,这是为什么? 我的程序是这样的: JSP程序: JavaBean CLASS...
配好 JDK+TOMCAT 环境后,就能用JAVABEAN吗?
我建好TOMCAT后(可以正常运行JSP程序),试图用一下JAVABEAN,程序特别简单,还是出错。哪位大哥能告诉我,这是为什么?
我的程序是这样的:
JSP程序:
JavaBean
CLASS程序:
package test;
public class TestBean{
public String TTT="This is a test.";
public String getText()
{
String temp=new String();
temp="Use Java Bean in JSP:"+TTT;
return temp;
}
}
错误信息:
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /test1.jsp
Generated servlet error:
C:tomcatworklocalhost_test1$jsp.java:60: Class test.TestBean not found.
test.TestBean testb = null;
^
An error occurred at line: 7 in the jsp file: /test1.jsp
Generated servlet error:
C:tomcatworklocalhost_test1$jsp.java:63: Class test.TestBean not found.
testb= (test.TestBean)
^
An error occurred at line: 7 in the jsp file: /test1.jsp
Generated servlet error:
C:tomcatworklocalhost_test1$jsp.java:68: Class test.TestBean not found.
testb = (test.TestBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "test.TestBean");
^
3 errors
at org.apache.jasper.compiler.Compiler.compile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
at java.lang.Thread.run(Thread.java:484)
我建好TOMCAT后(可以正常运行JSP程序),试图用一下JAVABEAN,程序特别简单,还是出错。哪位大哥能告诉我,这是为什么?
我的程序是这样的:
JSP程序:
JavaBean
CLASS程序:
package test;
public class TestBean{
public String TTT="This is a test.";
public String getText()
{
String temp=new String();
temp="Use Java Bean in JSP:"+TTT;
return temp;
}
}
错误信息:
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /test1.jsp
Generated servlet error:
C:tomcatworklocalhost_test1$jsp.java:60: Class test.TestBean not found.
test.TestBean testb = null;
^
An error occurred at line: 7 in the jsp file: /test1.jsp
Generated servlet error:
C:tomcatworklocalhost_test1$jsp.java:63: Class test.TestBean not found.
testb= (test.TestBean)
^
An error occurred at line: 7 in the jsp file: /test1.jsp
Generated servlet error:
C:tomcatworklocalhost_test1$jsp.java:68: Class test.TestBean not found.
testb = (test.TestBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "test.TestBean");
^
3 errors
at org.apache.jasper.compiler.Compiler.compile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
at java.lang.Thread.run(Thread.java:484)
|
package test;
public class TestBean{
public String TTT="This is a test.";
public TestBean() {}//可以加
public String getText()
{
String temp=new String();
temp="Use Java Bean in JSP:"+TTT;
return temp;
}
}
把生成的TestBean.class放到WEB-INFclassestest下
public class TestBean{
public String TTT="This is a test.";
public TestBean() {}//可以加
public String getText()
{
String temp=new String();
temp="Use Java Bean in JSP:"+TTT;
return temp;
}
}
把生成的TestBean.class放到WEB-INFclassestest下
|
如果你已经把你的TestBean.class放到WEB-INFclassesTestBean下了,你可以在jsp文件开始加一句话:
|
TestBean.class应该放到WEB-INFclassestest目录下,java中的包是跟目录相对应的,在tomcat和其它一些服务器中,WEB-INFclasses和WEB-INFlib(这儿放打包的类文件.jar)是包的根目录.
|
你的javabean放错地方了
|
把生成的TestBean.class放到WEB-INFclassesTestBean下