日期:2014-05-17  浏览次数:20752 次

javabean中getXxx()中是否可以添加其他语句
public double getArea()
{
double s;
double a=Double.valueOf(sideA);
double b=Double.valueOf(sideB);
double c=Double.valueOf(sideC);
if(sideA+sideB>sideC&&sideA+sideC>sideB&&sideB+sideC>sideA)
{

s=(sideA+sideB+sideC)/2.0;
area=Math.sqrt(s*(s-sideA)*(s-sideB)*(s-sideC));
area= Math.sqrt(s*(s-sideA)*(s-sideB)*(s-sideC));



}
return area;
}
这是我的bean中一得到输入3边后返回面积的getArea,老报错:description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Cannot find any information on property 'sum' in a bean of type 'mybean.test'
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:839)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1048)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1106)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
org.apache.jasper.compiler.Generator.generate(Generator.java:3365)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:315)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
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.18 logs


------解决方案--------------------
从你的错误信息:
org.apache.jasper.JasperException: Cannot find any information on property 'sum' in a bean of type 'mybean.test'
看出是因为没有 sum 这个属性!
------解决方案--------------------
好像是参照某个示例做的吧?
报错是因为没有sum对象,跟你的getArea没关系。

如果你真是参照的那个示例的话,把jsp里的sun 改成 area。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html