我写了一个javabean代码如下:
package test;import java.io.*;public class Circle2 {
double r = 1;
double circleArea = 0;
double circleLength = 0; public double gett() {
return r;
} public void setr(double nr) {
r = nr;
} public double getr() {
circleArea = Math.PI * r * r;
return circleArea;
} public double lengthr() {
circleLength = 2 * Math.PI * r;
return circleLength;
}}
jsp代码如下
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@page import="test.Circle2"%>
<html>
<head>
</head>
<body>
<jsp:useBean id="apple" class="test.Circle2" scope="page" />
<%apple.setr(100);%>
圆的半径为:<jsp:getProperty name= "apple" property= "r" />
</body>
</html>
为什么输出的的数为圆的周长,而且当property=circleArea或者=circleLength时就什么都出不来,我觉得不是代码的问题吧
谢谢!
package test;import java.io.*;public class Circle2 {
double r = 1;
double circleArea = 0;
double circleLength = 0; public double gett() {
return r;
} public void setr(double nr) {
r = nr;
} public double getr() {
circleArea = Math.PI * r * r;
return circleArea;
} public double lengthr() {
circleLength = 2 * Math.PI * r;
return circleLength;
}}
jsp代码如下
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@page import="test.Circle2"%>
<html>
<head>
</head>
<body>
<jsp:useBean id="apple" class="test.Circle2" scope="page" />
<%apple.setr(100);%>
圆的半径为:<jsp:getProperty name= "apple" property= "r" />
</body>
</html>
为什么输出的的数为圆的周长,而且当property=circleArea或者=circleLength时就什么都出不来,我觉得不是代码的问题吧
谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货