jsp的问题求助 sos~~~!
一个四则运算的页面HTML+JSP+JAVABEAN 型输入两个数字和运算符号即得运算结果但是无论我输入什么 最后总是显示 0.0文件存放的位置肯定没有问题麻烦大家帮我看看吧谢谢啦!代码如下JAVABEAN:package ch3;import java.io.*;public class plus{public plus(){}private String num1;private String num2;private double total;private String sign;public void setNum1(String num1){this.num1=num1;}public String getNum1(){return num1;}public void setNum2(String num2){this.num2=num2;}public String getNum2(){return num2;}public void setTotal(double total){this.total=total;}public double getTotal(){return total;}public void setSign(String sign){this.sign=sign;}public String getSign(){return sign;}public void cal(){double n1=Double.parseDouble(num1);double n2=Double.parseDouble(num2);try{if(sign=="+")total=n1+n2;else if(sign=="-")total=n1-n2;else if(sign=="*")total=n1*n2;else if(sign=="/")total=n1/n2;}catch(Exception e){System.out.println(e.toString());}}}HTML:<HTML><BODY><form name="t" action="plus.jsp" method="post">第一个数 <input type="text" name="num1" id="num1"><br>第二个数 <input type="text" name="num2" id="num2"><br>符号 <input type="text" name="sign" id="sign"><br><input type="submit" name="t1"></form></BODY></HTML>JSP:<%@ page language="java" contentType="text/html;charset=gb2312"%><jsp:useBean id="plus" class="ch3.plus"/><body><%String num1=request.getParameter("num1");String num2=request.getParameter("num2");String sign=request.getParameter("sign");plus.setNum1(num1);plus.setNum2(num2);plus.setSign(sign);plus.cal();%><center><%=plus.getTotal()%></center></body>
参考答案:if(sign=="+") 字符串行这样比较吗?没见过吖`
if(sign.equals("+"))