JAVA高手进...看看程序有没有错啊... NumberFormatException exc改完了这个其他的错应该也会没有了BTW:这不是什么高手问题,写Java要学会看错误信息 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主的jsp是手写的吧,建议用个带格式化的编辑器或者IDE写吧,在那里面写格式比较有保证,要不jsp很乱,还容易出错 <%@ page contentType="text/html; charset=gb2312" language="java"%><%@ page import="java.util.*"%><html><head><title>计算三角形面积</title></head><body><P>请输入三个边的长度: <BR><FORM NAME="form" Method="get" action="triangle.jsp"><p><InPut type="text" name="num1"></p><p><input type="text" name="num2"></p><p><input type="text" name="num3"></p><p><input type="submit" value="计算"></p></FORM><%! double a,b,c; String strA,strB,strC; String answer; double result;%><% if(request.getParameter("submit")!=null){ strA=request.getParameter("numl"); strB=request.getParameter("num2"); strC=request.getParameter("num3"); try{ a=Double.valueOf(strA); b=Double.valueOf(strB); c=Double.valueOf(strC); }catch(NumberFormatException exc){ out.println(" <BR>"+"请输入数字字符"); if((a+b)>c&&(a+c)>b&&(b+c)>a){ double p=(a+b+c)/2; result=Math.sqrt(p*(p-a)*(p-b)*(p-c)); out.println("面积为:"+result); } else{ answer="您输入的三边不能够成三角形"; out.print(" <BR>"+answer); } }}%></body></html> 看看行了没有 啊哦,手写jsp很好,可就怕写错单词、少加大括号....... 所以还是用IDE的好 下面这行代码错了:catch(NumberFormatExceptionexc){ 没有参数啊 还有就是想提醒一下lz在写html代码的时候,最好还是用标准的格式 全部用小写吧 你一会用大写的标签 一会又用小写的 看到很是不爽哦 你的代码的}写的有问题,在catch语句里表示出现异常才会执行的代码段,而你把整个计算面积的代码都圈在里面了.<%@ page contentType="text/html; charset=gb2312" language="java"%> <%@ page import="java.util.*"%> <html> <head> <title>计算三角形面积 </title> </head> <body> <P>请输入三个边的长度: <BR> <FORM NAME="form" Method="get" action="triangle.jsp"> <p> <InPut type="text" name="num1"> </p> <p> <input type="text" name="num2"> </p> <p> <input type="text" name="num3"> </p> <p> <input type="submit" value="计算"> </p> </FORM> <%! double a,b,c; String strA,strB,strC; String answer; double result; %> <% if(request.getParameter("submit")!=null){ strA=request.getParameter("numl"); strB=request.getParameter("num2"); strC=request.getParameter("num3"); try{ a=Double.valueOf(strA); b=Double.valueOf(strB); c=Double.valueOf(strC); }catch(NumberFormatException exc){ out.println(" <BR>"+"请输入数字字符"); } if((a+b)>c&&(a+c)>b&&(b+c)>a){ double p=(a+b+c)/2; result=Math.sqrt(p*(p-a)*(p-b)*(p-c)); out.println("面积为:"+result); } else{ answer="您输入的三边不能够成三角形"; out.print(" <BR>"+answer); } } %> </body> </html> 求教育 myclipse调试程序tomcat出错 *.jsp前面加“/”和不加"/"的区别是什么啊? 用j2ee的sdk写出来的程序,必须在某种容器里面才能运行么? 在div中用include导入jsp页面问题 请教大家一个路径问题 网页中嵌入摄像头的实时画面 一起努力spring(1):spring的国际化资源支持使用 关于文件操作的一个小问题,急,达人请... 请问我在JSP中调用JavaBean老是不成功,不知道JAR要放在什么地方怎么配置才行啊 Struts <logic:iterate> 标签问题 在hibernate中,Session 是不是类似 HttpSession ?
<%@ page import="java.util.*"%>
<html>
<head>
<title>计算三角形面积
</title>
</head>
<body>
<P>请输入三个边的长度: <BR>
<FORM NAME="form" Method="get" action="triangle.jsp">
<p>
<InPut type="text" name="num1">
</p>
<p>
<input type="text" name="num2">
</p>
<p>
<input type="text" name="num3">
</p>
<p>
<input type="submit" value="计算">
</p>
</FORM>
<%! double a,b,c;
String strA,strB,strC;
String answer;
double result;
%><%
if(request.getParameter("submit")!=null){
strA=request.getParameter("numl");
strB=request.getParameter("num2");
strC=request.getParameter("num3");
try{
a=Double.valueOf(strA);
b=Double.valueOf(strB);
c=Double.valueOf(strC);
}catch(NumberFormatException exc){
out.println(" <BR>"+"请输入数字字符");
if((a+b)>c&&(a+c)>b&&(b+c)>a){
double p=(a+b+c)/2;
result=Math.sqrt(p*(p-a)*(p-b)*(p-c));
out.println("面积为:"+result);
} else{
answer="您输入的三边不能够成三角形";
out.print(" <BR>"+answer);
}
}
}
%>
</body>
</html> 看看行了没有
catch(NumberFormatExceptionexc){
没有参数啊 还有就是想提醒一下lz在写html代码的时候,最好还是用标准的格式 全部用小写吧 你一会用大写的标签 一会又用小写的 看到很是不爽哦
你的代码的}写的有问题,在catch语句里表示出现异常才会执行的代码段,而你把整个计算面积的代码都圈在里面了.
<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>计算三角形面积
</title>
</head>
<body>
<P>请输入三个边的长度: <BR>
<FORM NAME="form" Method="get" action="triangle.jsp">
<p>
<InPut type="text" name="num1">
</p>
<p>
<input type="text" name="num2">
</p>
<p>
<input type="text" name="num3">
</p>
<p>
<input type="submit" value="计算">
</p>
</FORM>
<%! double a,b,c;
String strA,strB,strC;
String answer;
double result;
%> <%
if(request.getParameter("submit")!=null){
strA=request.getParameter("numl");
strB=request.getParameter("num2");
strC=request.getParameter("num3");
try{
a=Double.valueOf(strA);
b=Double.valueOf(strB);
c=Double.valueOf(strC);
}catch(NumberFormatException exc){
out.println(" <BR>"+"请输入数字字符");
}
if((a+b)>c&&(a+c)>b&&(b+c)>a){
double p=(a+b+c)/2;
result=Math.sqrt(p*(p-a)*(p-b)*(p-c));
out.println("面积为:"+result);
} else{
answer="您输入的三边不能够成三角形";
out.print(" <BR>"+answer);
}
}
%>
</body>
</html>