JavaBean在JSP中的有效范围 5
Box.java如下:packagecom.jsfabc.jsh.view.bean;publicclassBox{privateintlength;privateint...
Box.java如下:
package com.jsfabc.jsh.view.bean;
public class Box {
private int length;
private int width;
private int height;
private int vol;
public Box(){
}
private void setLength(int length) {
this.length = length;
}
private int getLength() {
return length;
}
private void setWidth(int width) {
this.width = width;
}
private int getWidth() {
return width;
}
private void setHeight(int height) {
this.height = height;
}
private int getHeight() {
return height;
}
public void setVol()
{
vol=length*width*height;
}
}
beanScope1.jsp文件如下:
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.jsfabc.jsh.view.bean.Box"%>
<html>
<head>
<title>bean scope page</title>
</head>
<body>
<jsp:useBean id="box" class="com.jsfabc.jsh.view.bean.Box" scope="page">
</jsp:useBean>
<jsp:setProperty name="box" property="length" value="2"/>
<jsp:setProperty name="box" property="width" value="3"/>
<jsp:setProperty name="box" property="height" value="4"/>
盒子的体积是:<jsp:getProperty name="box" property="vol"/>
</body>
</html>
当在浏览中输入地址:http://127.0.0.1:8080/JSP_JavaBean/beanScope1.jsp
显示出错:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /beanScope1.jsp(8,0) The value for the useBean class attribute com.jsfabc.jsh.view.bean.Box is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1220)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Generator.generate(Generator.java:3416)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:231)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs. 展开
package com.jsfabc.jsh.view.bean;
public class Box {
private int length;
private int width;
private int height;
private int vol;
public Box(){
}
private void setLength(int length) {
this.length = length;
}
private int getLength() {
return length;
}
private void setWidth(int width) {
this.width = width;
}
private int getWidth() {
return width;
}
private void setHeight(int height) {
this.height = height;
}
private int getHeight() {
return height;
}
public void setVol()
{
vol=length*width*height;
}
}
beanScope1.jsp文件如下:
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.jsfabc.jsh.view.bean.Box"%>
<html>
<head>
<title>bean scope page</title>
</head>
<body>
<jsp:useBean id="box" class="com.jsfabc.jsh.view.bean.Box" scope="page">
</jsp:useBean>
<jsp:setProperty name="box" property="length" value="2"/>
<jsp:setProperty name="box" property="width" value="3"/>
<jsp:setProperty name="box" property="height" value="4"/>
盒子的体积是:<jsp:getProperty name="box" property="vol"/>
</body>
</html>
当在浏览中输入地址:http://127.0.0.1:8080/JSP_JavaBean/beanScope1.jsp
显示出错:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /beanScope1.jsp(8,0) The value for the useBean class attribute com.jsfabc.jsh.view.bean.Box is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1220)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Generator.generate(Generator.java:3416)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:231)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs. 展开
5个回答
展开全部
首先:你的setX与getX函数必须都设置为公有访问权限的(这是规定)
另外:你的JSP文件里面:<jsp:useBean id="box" class="com.jsfabc.jsh.view.bean.Box" scope="page">
</jsp:useBean>
这句也有错,,应该使用空标签即:<jsp:useBean id="box" class="com.jsfabc.jsh.view.bean.Box" scope="page"/>
,你改改吧,,如果还有问题,可以继续提问。。。
另外:你的JSP文件里面:<jsp:useBean id="box" class="com.jsfabc.jsh.view.bean.Box" scope="page">
</jsp:useBean>
这句也有错,,应该使用空标签即:<jsp:useBean id="box" class="com.jsfabc.jsh.view.bean.Box" scope="page"/>
,你改改吧,,如果还有问题,可以继续提问。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
BOX中没有vol属性的get方法,<jsp:getProperty name="box" property="vol"/>编译会出错,添加:
public int getVol() {
return length*width*height;
}
即可,set方法写不写无所谓
public int getVol() {
return length*width*height;
}
即可,set方法写不写无所谓
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
org.apache.jasper.JasperException: /beanScope1.jsp(8,0) The value for the useBean class attribute com.jsfabc.jsh.view.bean.Box is invalid
说你 “com.jsfabc.jsh.view.bean.Box”这个路径非法
说你 “com.jsfabc.jsh.view.bean.Box”这个路径非法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你看下你发布到Tomcat的项目对不,异常的意思是你的bean不可用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
重启服务器,然后发布项目之后试试看?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询