/******MyJsp3.jsp的全部代码*********/
<%@ page language="java" import="java.util.*" contentType="text/html;charset=GB2312" pageEncoding="GB2312"%><%@ page import="java.io.*" %><%@ page import="javax.servlet.*" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>">
<title>My JSP 'MyJsp3.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->
</head>
<body bgcolor="cyan"> This is my JSP page. <br> <font size="1"> <p> 输入三角形三边长度,用逗号隔开:<br> <form action="MyJsp3" method="post" name="form"> <input type="text" name="boy"> <input type="submit" value="送出" name="submit"> </form> </font> <%! double a[]=new double[3]; String answer=null; %> <%int i=0; boolean b=true; String s=null; double result=0; double a[]=new double[3]; String answer=null; s=request.getParameter("boy"); if(s!=null) { StringTokenizer fenxi=new StringTokenizer(s,","); while(fenxi.hasMoreTokens()) { String temp=fenxi.nextToken(); try { a[i]=Double.valueOf(temp).doubleValue(); i++; } catch(NumberFormatException ex) { out.print("<br>"+"请输入数字字符"); } } if(a[0]+a[1]>a[2]&&a[0]+a[2]>a[1]&&a[1]+a[2]>a[0]&&b==true) { double p=(a[0]+a[1]+a[2])/2; result=Math.sqrt(p*(p-a[0])*(p-a[1])*(p-a[2])); out.println("面积:"+result); } else { answer="您输入的三边不构成三角形。"; out.println("<br>"+answer); } } %> <p> 您输入的三边是:<br> <%=a[0] %><br> <%=a[1] %><br> <%=a[2] %><br></body></html>
打开是这样的下图,输入3,4,5 然后点按钮
结果出现错误
添加回答
举报
0/150
提交
取消