首页 新闻 会员 周边 捐助

JSP跳转获取不到参数

0
悬赏园豆:10 [已解决问题] 解决于 2012-12-25 19:58

/******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  然后点按钮

结果出现错误

午饭惊魂的主页 午饭惊魂 | 初学一级 | 园豆:195
提问于:2012-12-25 18:56
< >
分享
最佳答案
0

很简单,action="MyJsp3"里面忘了加后缀名,应该是action="MyJsp3.jsp"。哎呀搞了一天才开窍

午饭惊魂 | 初学一级 |园豆:195 | 2012-12-25 19:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册