JSP中使用JavaBean出现异常,求各位大侠帮忙指导.
JSP中使用JavaBean出现异常,求各位大侠帮忙指导.我的代码如下:Circle.javapackagetom;publicclassCircle{intradius...
JSP中使用JavaBean出现异常,求各位大侠帮忙指导.
我的代码如下:
Circle.java
package tom;
public class Circle
{
int radius = 1;
public Circle()
{
radius=1;
}
public int getRadius()
{
return radius;
}
public void setRadius(int newRadius)
{
radius=newRadius;
}
public double circleArea()
{
return Math.PI*radius*radius;
}
public double circlLength()
{
return 2.0*Math.PI*radius;
}
}
useBean.jsp
<%@ page contentType="text/html;charset=GB2312" pageEncoding="gb2312"%>
<%@ page import="tom.jiafei.*"%>
<HTML>
<BODY bgcolor=lightgray><Font size=5>
<jsp:useBean id="girl" class="tom.Circle" scope="page">
</jsp:useBean>
<%girl.setRadius(100); %>
<P>
圆的半径是:
<%=girl.getRadius()%>
<P>
圆的周长是:
<%=girl.circlLength()%>
<P>
圆的面积是:
<%=girl.circleArea()%>
</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: /J2EETest/WebRoot/useBean.jsp(6,5) The value for the useBean class attribute tom.Circle 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:1229)
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:3440)
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:592)
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.29 logs.
<%@ page import="tom.Circle"> 我导入了还是一样的问题 展开
我的代码如下:
Circle.java
package tom;
public class Circle
{
int radius = 1;
public Circle()
{
radius=1;
}
public int getRadius()
{
return radius;
}
public void setRadius(int newRadius)
{
radius=newRadius;
}
public double circleArea()
{
return Math.PI*radius*radius;
}
public double circlLength()
{
return 2.0*Math.PI*radius;
}
}
useBean.jsp
<%@ page contentType="text/html;charset=GB2312" pageEncoding="gb2312"%>
<%@ page import="tom.jiafei.*"%>
<HTML>
<BODY bgcolor=lightgray><Font size=5>
<jsp:useBean id="girl" class="tom.Circle" scope="page">
</jsp:useBean>
<%girl.setRadius(100); %>
<P>
圆的半径是:
<%=girl.getRadius()%>
<P>
圆的周长是:
<%=girl.circlLength()%>
<P>
圆的面积是:
<%=girl.circleArea()%>
</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: /J2EETest/WebRoot/useBean.jsp(6,5) The value for the useBean class attribute tom.Circle 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:1229)
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:3440)
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:592)
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.29 logs.
<%@ page import="tom.Circle"> 我导入了还是一样的问题 展开
展开全部
<%@ page import="tom.jiafei.*"%>
改成
<%@ page import="tom.*"%>
<jsp:useBean id="girl" class="tom.Circle" scope="page">
改成
<jsp:useBean id="girl" class="Circle" scope="page">
试试
改成
<%@ page import="tom.*"%>
<jsp:useBean id="girl" class="tom.Circle" scope="page">
改成
<jsp:useBean id="girl" class="Circle" scope="page">
试试
更多追问追答
追问
我导入了还是一样的问题
我用的是MyEclipse开发,我没做任何配置,是不是要什么配置啊
追答
不是配置的问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个问题是因为你没有在spring的配置文件中配置所要bean的标签吧
追问
哦,我初学在JSP中使用JavaBean,还不知道有配置这回事,能不能请教下怎么配置
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%@ page import="tom.jiafei.*"%>
没有将Circle类(package tom)导入而已!
加上<%@ page import="tom.Circle">
没有将Circle类(package tom)导入而已!
加上<%@ page import="tom.Circle">
更多追问追答
追问
我导入了还是一样的问题
追答
圆的半径是:
圆的周长是:
圆的面积是:
这样就可以了!把那一段放到标签里面
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把radius属性设为private看看
追问
我用的是MyEclipse开发,我没做任何配置,是不是要什么配置啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询