JSP计算器
Posted Jone雄大
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSP计算器相关的知识,希望对你有一定的参考价值。
<%@ page language= "java" contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta charset="utf-8">
<title>计算器</title>
</head>
<body>
<hr>
<%!
double num1 = 0.0;
double num2 = 0.0;
double result=0.0;
boolean dispaly= false;
%>
计算结果:
<%
String num3=request.getParameter("num1");
String num4=request.getParameter("num2");
String zifu = request.getParameter("zifu");
if(num3!=null&&num4!=null&&zifu!=null){
num1=Double.valueOf(num3);
num2=Double.valueOf(num4);
if("+".equals(zifu)){
result=num1+num2;
}else if("-".equals(zifu)){
result=num1-num2;
}else if("*".equals(zifu)){
result=num1*num2;
}else if("/".equals(zifu)){
result=num1/num2;
}else{
;
}
dispaly=true;
}
%>
<%if(dispaly){%>
<%=num1 %><%=zifu %><%=num2 %>=<%=result %>
<% } %>
<form action="cal.jsp" method="post">
<table border = 1 align="center">
<tr>
<td>操作数1:<input type="text" name="num1"></td>
</tr>
<tr>
<td>字符:
<select name="zifu" id="">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</td>
</tr>
<tr>
<td>操作数2:<input type="text" name="num2"></td>
</tr>
<tr>
<td colspan="2"> <input type="submit" value="结果"></td>
</tr>
</table>
</form>
</body>
</html>
以上是关于JSP计算器的主要内容,如果未能解决你的问题,请参考以下文章