付费节点推荐
免费节点
节点使用教程
<%@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>
未经允许不得转载:Bcoder资源网 » jsp制作简单计算器
评论前必须登录!
登陆 注册