代码:
1 <body> 2 <% 3 String a1 =""; 4 String a2 = ""; 5 long s = 0; 6 a1 = request.getParameter("aa"); 7 a2 = request.getParameter("bb"); 8 String outs=""; 9 if(a1!=null && !a1.trim().equals("") && a2!=null && !a2.trim().equals("")){ 10 try{ 11 s = Long.parseLong(a1)+Long.parseLong(a2); 12 outs = String.valueOf(s); 13 }catch(Exception ex){ 14 outs="您输入的不是有效数字!"; 15 } 16 } 17 if(a1==null||a2==null) { 18 a1 =""; 19 a2 = ""; 20 } 21 %> 22 23 <h1>整型加法计算</h1> 24 <form name="form1" action="" method="post"> 25 <input type="text" name="aa" id="aa" value="<%=a1%>"/>+ 26 <input type="text" name="bb" id="bb" value="<%=a2%>"/>= 27 <input type="text" name="s" id="s" value="<%=outs%>"/> 28 <br> 29 <input type="submit" name="submit1" value="计算"/> 30 </form> 31 </body>
运行结果: