日期:2014-05-18  浏览次数:20714 次

很多人都想办法了,可找不到原因!
MathBeab.java
___________________________________________________
package   test;

public   class   MathBean   {
      private   String   a;
      private   String   b;
      private   double   result;
      private   String   operator;
public   String   getA()   {
if(a==null)
a= " ";
return   a;
}
public   void   setA(String   a)   {

this.a   =   a;
}
public   String   getB()   {
if(b==null)
b= " ";
return   b;
}
public   void   setB(String   b)   {
this.b   =   b;
}
public   String   getOperator()   {
return   operator;
}
public   void   setOperator(String   operator)   {
this.operator   =   operator;
}
public   double   getResult()   {
return   result;
}
public   void   forResult()   {
double   one=Double.parseDouble(a);
double   two=Double.parseDouble(b);
try   {
if   (this.equals( "+ "))   result=one+two;
else   if   (this.equals( "- "))   result=one-two;
else   if   (this.equals( "* "))   result=one*two;
else   if   (this.equals( "/ "))   result=one/two;
}   catch   (Exception   e)   {
e.printStackTrace();
//   TODO:   handle   exception
}
}
}
___ForRrsult.JSP________________________________________
<%@   page   language= "java "   contentType= "text/html;charset=gb2312 "%>
<%@   page   import= "java.sql.* "%>
<jsp:useBean   id= "forResult "class= "test.MathBean "scope= "request ">
<jsp:setProperty   name= "forResult "   property= "* "/>
</jsp:useBean>
<html>
    <head>
    <meta     http-equiv= "content-type "       content= "text/html;   charset=gb2312 "/>
       
        <title>   一简单的计数器 </title>
       
       
    </head>
    <body> <center>
            <form   action= "forResult.jsp "   method= "POST ">
                        <table   border= "1 "   width= "300 "bgcolor= "#ffffc0 ">
                            <tr> <td> 计算结果 </td>
                            <%
                                      try{forResult.forResult();}
                                            catch(