I am trying to get my getProperty to work in my JSP page.
My results show a blank where it should show me the average:
Counts on web pages: 40.0 -- 50.0 -- Average now equal to
My JSP page:
Code:
<jsp:useBean id="myStat" class="colors.myStatBean">
<%
double[] theNumbers = {40, 50};
myStat.setNumbers(theNumbers);
%>
</jsp:useBean>
<html>
<body>
Counts on web pages:
<%
double[] numbers = myStat.getNumbers();
for(int i = 0;i < numbers.length;i++)
{
out.println(numbers[i] + " -- ");
}
%>
Average now equal to
<jsp.getProperty name="myStat" property="getAverage"/>
<%-- I also tried with property="average" and it also gave me a blank output --%>
</body>
</html>
The Java file:
Code:
package colors;
import java.util.*;
public class myStatBean
{
private double[] numbers;
//constructor
public myStatBean()
{
numbers = new double[2];
numbers[0] = 1;
numbers[1] = 2;
}
public double getAverage()
{
double sum = 0;
for (int i=0;i < numbers.length;i++)
sum += numbers[i];
return sum/numbers.length;
}
public double[] getNumbers()
{
return numbers;
}
public void setNumbers(double[] numbers)
{
this.numbers = numbers;
}
}