- ·上一篇文章:Jsp之Tag文件和Tag标记
- ·下一篇文章:JSP Cookies
jsp制作简单计算器
-->
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | <%@page import="jdk.nashorn.internal.ir.RuntimeNode.Request"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <title>jsp计算器</title> </head> <body> <h2>简单计算器</h2> <form action="" method="post" name="form"> <input type="text" name="num1"> <Select name="operator"> <Option value="+">+ <Option value="-">- <Option value="*">* <Option value="/">/ </Select> <input type="text" name="num2"> = <br /> <br /> <input type="submit" value ="计算" name="submit"> </form> <% String num1=request.getParameter("num1"); String num2=request.getParameter("num2"); String operator=request.getParameter("operator"); float res=0f; if(num1!=null && num2!=null){ float a=Float.parseFloat(num1); float b=Float.parseFloat(num2); if(operator.equals("+")){ res=a+b; } else if(operator.equals("-")){ res=a-b; } else if(operator.equals("*")){ res=a*b; } else res=a/b; } %> <p>结果为:<%= res %> </p> </body> </html> |
jsp制作简单计算器