编写jsp程序实现简易的加法运算器
发布网友
发布时间:2023-01-26 02:20
我来回答
共1个回答
热心网友
时间:2024-11-30 08:38
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String a1 ="";
String a2 = "";
long s = 0;
a1 = request.getParameter("a1");
a2 = request.getParameter("a2");
String outs="";
if(a1!=null && !a1.trim().equals("") && a2!=null && !a2.trim().equals("")){
try{
s = Long.parseLong(a1)+Long.parseLong(a2);
outs = String.valueOf(s);
}catch(Exception ex){
outs="您输入的不是有效数字!";
}
}
if(a1==null||a2==null) {
a1 ="";
a2 = "";
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>max</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<form name="form1" action="" method="post">
<input type="text" name="a1" id="a1" value="<%=a1%>"/>+
<input type="text" name="a2" id="a2" value="<%=a2%>"/>=
<input type="text" name="s" id="s" value="<%=outs%>"/>
<input type="submit" name="submit1" value="计算"/>
</form>
</body>
</html>