JavaBean老是连不上,急急急!

apsu 2003-11-17 10:06:09
JAVABEAN 叫UserData.class
把JAVABEAN 放在F:\JSP\Data\userData\WEB-INF\classes\test下
JSP文件放在F:\JSP\Data\userData下
UserData.class内容如下:

package test;
public class UserData
{
private String Name;
private String Num;
public UserData()
{
}
public void setUserName(String name)
{
Name=name;
}
public void setUserNum(String num)
{
Num=num;
}
public String getUserName()
{
return Name;
}
public String getUserNum()
{
return Num;
}
}

JSP内容如下:

<html>
<title>设定JavaBean中的属性</title>
<body>
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import = "test.UserData"%>
<jsp:useBean id="data" scope="session" class="test.UserData"/>
<%
data.setUserName("apsu");
data.setUserNum("211");
%>
姓名:<%=data.getUserName()%>
分机号码:<%=data.getUserNum()%>
</body>
</html>


运行后有错! 提示如下:

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: 5 in the jsp file: /userData/index.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Tomcat\work\Standalone\localhost\Data\userData\index_jsp.java:7: package test does not exist
import test.UserData;
^
C:\Tomcat\work\Standalone\localhost\Data\userData\index_jsp.java:48: package test does not exist
test.UserData data = null;
^



An error occurred at line: 5 in the jsp file: /userData/index.jsp

Generated servlet error:
C:\Tomcat\work\Standalone\localhost\Data\userData\index_jsp.java:50: package test does not exist
data = (test.UserData) pageContext.getAttribute("data", PageContext.SESSION_SCOPE);
^



An error occurred at line: 5 in the jsp file: /userData/index.jsp

Generated servlet error:
C:\Tomcat\work\Standalone\localhost\Data\userData\index_jsp.java:53: package test does not exist
data = (test.UserData) java.beans.Beans.instantiate(this.getClass().getClassLoader(),

"test.UserData");
^
4 errors


at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at

org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at

org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at

org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at

org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at

org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at

org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)


望高手指点! 我一直没成功过,去掉包,重新编译成.CLASS文件直接放在WEB-INF\CLASS\下也不行!
...全文
9 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
apsu 2003-11-20
谢谢大家,问题已经解决了,是我自己设置的问题!
回复
jndszl 2003-11-18
<%@ page import = "test.UserData"%>去了
回复
apsu 2003-11-18
而且这个JAVABEAN是必须打包的,不打包放在那里也不行!
回复
apsu 2003-11-18
JAVABEAN如果不是放在放入 Tomcat41\common\classes\
再怎么样也没用,是不是我的设置不对啊?
好像JAVABEAN也没有什么设置的吧?我想只要写对了,路径对了就可以了
但虚拟目录下的WEB-INF\CLASSES 老是不行啊?

神啊,救救我吧!
回复
majunbo 2003-11-18
this.Name=name;

加上this
回复
noratong 2003-11-18
你在Tomcat中设置了你的web文件的上下文没有????
也就是在你的Tomcat的conf目录下的的server.xml中加入这个没:
<Context path="/userData"这个是你在浏览器中输入的路径,加在8080后面. docBase="F:\JSP\Data\userData" debug="0"/>

照说你的部署都是对的呀,只要你设置了上下文就一定可以访问.

还有javabean在Tomcat5中使用必须要打包才能使用,Tomcat4好像也是一样的.
回复
secball 2003-11-18
你也可以将Bean放在tomcat\webapps\ROOT\WEB-INF下,但你要要里面创建classes目录并将bean放到这个目录中,还要将tomcat\webapps\ROOT\WEB-INF\classes加进classpath。JSP文件放在tomcat\webapps\ROOT\下(也可以创建自己目录)。最后
http://localhost:8080/xx.jsp则可
回复
secball 2003-11-18
如果是Tomcat的话,你又懒一点的话把bean放到D:\tomcat\webapps\examples\WEB-INF\classes\test\下.JSP文件放到D:\tomcat\webapps\examples\jsp\下
然后http://localhost:8080/examples/jsp/t.jsp就可以啦!
回复
eureka0891 2003-11-18
<%@ page import = "test.UserData"%>
不用
回复
chenyubang 2003-11-18
对必须打包才可使用,应该保存为UserData.java也可以
回复
apsu 2003-11-17
to gjd111686:
放入\Apache Group\Tomcat41\common\classes
是可以连上的,但是为什么我放下自己的虚拟目录
下就不行呢?
回复
gjd111686 2003-11-17
与<%@ page import = "test.UserData"%>没有关系.
1.放入\Apache Group\Tomcat41\common\classes路径下试试.
2.在CLASSPATH中直接指定路径试试
回复
giftxi 2003-11-17
<%@ page import = "test.UserData"%>去掉这句话试试看。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-11-17 10:06
社区公告
暂无公告