日期:2014-05-17 浏览次数:20688 次
<html> <body> <form action="calculate.jsp" method="get"> 第一个参数:<input type="text" name="first"> <br>操作运算符: <select name="operator"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select><br> 第二个参数:<input type="text" name="second"> <br><input type="submit" value="计算"> </form> </body> </html>
<%@ page language="java" contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%> <jsp:useBean id="calculator" scope="request" class=MyBean.SimpleCalculate"> <jsp:setProperty property="*" name="calculator"/> </jsp:useBean> <html> <body> <hr> 计算结果:<% try{ calculator.calculate(); out.println(calculator.getfirst()+calculator.getoperator()+calculator.getsecond()+"="+calculator.getresult()); } catch(Exception e) { out.println(e.getMessage()); } %> </body> </html>