/******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 ?然后點按鈕
結果出現錯誤
JSP跳轉獲取不到參數
寶慕林4294392
2018-12-06 12:08:36