汽修职业技能大赛:java:请帮个javaBean的忙,必加100分
来源:百度文库 编辑:神马品牌网 时间:2024/10/03 02:36:47
public class test{
private String first;
private String second;
private double result;
private String opertator;
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 calculte(){
double one=Double.parseDouble(first);
double two=Double.parseDouble(second);
try{
if(operator.equals("+"))result=one+two;
else if(operator.equals("*"))result=one*two;
}catch(Exception e){
System.out.println(e);
}
}
}
上面只是这个javabean程序!
调用用下面的方法:
<jsp:userbean id="calculator" scope="request" class="类路径">
<jsp:setProperty name=calculator" property="*"/>
</jsp:userbean>
<%
try{
calcutor.calculate();
out.println(calculator.getFirst()+calculator.getOperator()+calculator.getSecond()+"="+calculator.getResult())
}catch(Exception e)
{
out.println(e.getMessage())
}
%>