初学者一个简单的javaBean问题(送分问题)

love89 2004-10-06 09:35:56
我是刚学jsp,以前用过php,asp等。但在用javaBean时发现一些小问题,请各位朋友帮忙下。

类的代码如下:
package bean;
public class sampleBean
{
private String sample = "Start value";
public String getSample() {
return sample;
}
public void setSample(String newValue) {
if(newValue != null) {
sample = newValue;
}
}
}

我将它生成sampleBean.class, 并放在Tomcat 5.0/webapps/ROOT/WEB-INF/classes 里面,并已经重启。


用sample.jsp 调用这个类。
<%@ page contentType="text/html;charset=GBK"%>
<html>
<head>
<title>Servlet使用JSP</title>
</head>
<jsp:useBean id="myBean"
scope="application" class="bean.sampleBean"/>
<body bgcolor="gray">
<h2>JSP使用JavaBean的例子:</h2>
<hr>
调用jsp:setProperty之前的值:
<jsp:getProperty name="myBean" property="sample"/>
<p>
<jsp:setProperty name="myBean"
property="sample" value="hhhhhhhhhhhhh"/>
调用jsp:setProperty之后的值:
<jsp:getProperty name="myBean1" property="sample"/>
</body>
</html>


但调试时没有通过,出现以下错误。
type Exception report

message

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

exception

org.apache.jasper.JasperException: /sample1.jsp(6,1) The value for the useBean class attribute bean.sampleBean is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.


请问是何原因,谢谢!
...全文
271 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
qingqing82 2004-10-07
  • 打赏
  • 举报
回复
就是jsp:getProperty name="myBean1" property="sample"/>这里的错!我试过了上面的例子通过了!
laughsmile 2004-10-07
  • 打赏
  • 举报
回复
你的代码中,如下不是定义了sample么
.........
public class sampleBean
{
private String sample = "Start value";
....
}

出现错误的原因,如下:
1.应该把JavaBean放在Tomcat 5.0/webapps/ROOT/WEB-INF/classes/bean中
2.最后一个<jsp:getProperty name="myBean1" property="sample"/>
love89 2004-10-07
  • 打赏
  • 举报
回复
sample名字是那里定义的。
pxsaner 2004-10-07
  • 打赏
  • 举报
回复
sampleBean.class应该放在Tomcat 5.0\webapps\ROOT\WEB-INF\classes\bean目录下,而且<jsp:getProperty name="myBean1" property="sample"/>这里有错,改成这个:<jsp:getProperty name="myBean" property="sample"/>
Ellion 2004-10-07
  • 打赏
  • 举报
回复
在Tomcat 5.0/classes 里面建个名字叫bean的文件夹(因为在sample.jsp 调用这个类你的class="bean.sampleBean")把生成的sampleBean.class放在Tomcat 5.0/classes/bean里面!
我觉得就可以了,至于你的jdk和tomcat的路径因该是没问题的!
bluejack1122 2004-10-06
  • 打赏
  • 举报
回复
sameBean 的类名是不是有误啊!!SameBean 是不是该这样写啊!!1我看你的类名第一个是小写的。
alexlooks 2004-10-06
  • 打赏
  • 举报
回复
老大们 我也是初学者,也是同样的程序提示错误:
JSP Parsing Error:Cannot find any information on property 's' in a bean of type 'test.TestBean'

只是类名和包名不同而已,借此地问问^_^
love89 2004-10-06
  • 打赏
  • 举报
回复
javac -d . sampleBean.java的格式是怎样的,

javac -d是什么意思?
MARS.nEIL 2004-10-06
  • 打赏
  • 举报
回复
sample.jsp里边的<jsp:getProperty name="myBean1" property="sample"/>应该为
<jsp:getProperty name="myBean" property="sample"/>
pioul 2004-10-06
  • 打赏
  • 举报
回复
把你的sampleBean.java放在classes下面,然后javac -d . sampleBean.java
就可以了
love89 2004-10-06
  • 打赏
  • 举报
回复


我将 sampleBean.class 放在 bean文件夹里,但仍出现以下错误信息,没办法,jsp的出错信息比较难明白,还是劳烦高手指点下,谢谢!







pe Exception report

message

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

exception

org.apache.jasper.JasperException: Attempted a bean operation on a null object.
org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(JspRuntimeLibrary.java:601)
org.apache.jsp.sample1_jsp._jspService(sample1_jsp.java:68)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs
dragon2005 2004-10-06
  • 打赏
  • 举报
回复
class="bean.sampleBean"

bean 是你的包名,
sampleBean是你的类名

在classes下面建一个bean目录,把你的类放入即可。


ricky921 2004-10-06
  • 打赏
  • 举报
回复
sampleBean.class应该先放在bean这个文件下面 再把这个文件放到WEB-INF/classes 下面
zhbw 2004-10-06
  • 打赏
  • 举报
回复
应该配置CLASSPATH环境变量吧
love89 2004-10-06
  • 打赏
  • 举报
回复
sampleBean.class 应该怎样放呀
MARS.nEIL 2004-10-06
  • 打赏
  • 举报
回复
javabean没有找到...sampleBean.class路径不对...
huly2000 2004-10-06
  • 打赏
  • 举报
回复
楼上正解
PK5261 2004-10-06
  • 打赏
  • 举报
回复
<jsp:getProperty name="myBean1" property="sample"/>这里有错

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧