日期:2014-05-17 浏览次数:20880 次
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="test.Calculate" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="suan" scope="application" class="test.Calculate"></jsp:useBean>
<%
String str1=request.getParameter("num1");
String str2=request.getParameter("num2");
String item = request.getParameter("item");
try{
Double num1=Double.parseDouble(str1.trim());
Double num2=Double.parseDouble(str2.trim());
suan.setNum1(num1);
suan.setNum2(num2);
if(item.equals("+")){
out.println(num1+"+"+num2+"="+(num1+num2));
}
}catch(Exception e){
out.println("有例外发生!");
}
%>
</body>
</html>
package test;
public class Calculate {
private double num1;
private double num2;
private String operator;
public void setNum1 (double num1)
{this.num1=num1;}
public void setNum2 (double num2)
{this.num2=num2;}
public double getNum1()
{return num1;}
public double getNum2()
{return num2;}
public double jia(){
double num3=num1+num2;
return num3;
}
public double jian(){
double num3=num1-num2;
return num3;
}
public double cheng(){
double num3=num1*num2;
return num3;
}
public double chu(){
double num3=num1/num2;
return num3;
}
}
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.util.*" %>