刚学JSP,遇见错误怎么改
bean代码:package com.ch1;
public class SimpleCalculator
{ private String first;
private String second;
private double result;
private String operator;
public void setFirst(String first)
{
this.first=first;
}
public void setSecond(String second)
{
this.second=second;
}
public void setOperator(String operator)
{
this.operator=operator;
}
public String getFirst()
{
return this.first;
}
public String getSecond()
{
return this.second;
}
public String getOperator()
{
return this.operator;
}
public double getResult()
{
return this.result;
}
public void calculate()
{
double one=Double.parseDouble(first);
double two=Double.parseDouble(second);
try
{
if(operator.equals("+") ) result=one+two;
else if (operator.equals("-") ) result=one-two;
else if (operator.equals("*") ) result=one*two;
else if (operator.equals("/") ) result=one/two;
}
catch(Exception e)
{
System.out.println(e);
}
}
}
JSP页面代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"
error page=""%>
<jsp:useBean id="calculator" scope="request" class="com.ch1.SimpleCalculator">
<jsp:setProperty name="calculator" property="*"/>
</jsp:useBean>
<html>
<head>
<title> 简单计算器</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<hr>
计算结果:<%
try
{
calculator.calculate();
out.println(calculator.getFirst()+calculator.getOperator()+calculator.getSecond()+"="+calculator.getResult());
}
catch(Exception e)
{
out.println(e.getMessage());
}
%>
<hr>
<form action="calculate.jsp" method=get>
<table width="75%" border="1" bordercolor="#003300">
<tr bgcolor="#999999">
<td colspan="2">简单的计算器</td>
</tr>
<tr>
<td>第一个参数</td>
<td><input type=text name="first"></td>
</tr>
<tr>
<td>操作符</td>
<td><Select name="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</td>
</tr>
<tr><td>第二个参数</td>
<td><input type=text name="second"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#cccccc"><input type=submit value=计算></td>
</tr>
</table></form></body></html>