编写一个JSP页面
编写一个JSP页面:计算圆周长和面积experiment1_2.jsp具体要求:声明long型变量length和area,为整个页面使用;声明2个方法计算圆周长conti...
编写一个JSP页面:
计算圆周长和面积experiment1_2.jsp
具体要求:
声明long型变量length和area,为整个页面使用;
声明2个方法计算圆周长continueLength和面积continueArea;
页面显示:周长和面积 展开
计算圆周长和面积experiment1_2.jsp
具体要求:
声明long型变量length和area,为整个页面使用;
声明2个方法计算圆周长continueLength和面积continueArea;
页面显示:周长和面积 展开
2个回答
展开全部
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%!
public double circleArea(double radius) {
return Math.PI * radius * radius;
}
public double circlLength(double radius) {
return 2.0 * Math.PI * radius;
}
%>
<%
String lengthharf = request.getParameter("lengthharf");
double area = 0.0;
double lent = 0.0;
try{
double tempValue = Double.valueOf(lengthharf);
area = circleArea(tempValue);
lent = circlLength(tempValue);
}catch(Exception e){
e.printStackTrace();
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<form action="experiment1_2.jsp" method="post">
请输入半径:<input type="text" name="lengthharf">
<input type="submit" name="提交">
</form>
圆周长:<%=lent %>
面积:<%=area %>
</body>
</html>
<%!
public double circleArea(double radius) {
return Math.PI * radius * radius;
}
public double circlLength(double radius) {
return 2.0 * Math.PI * radius;
}
%>
<%
String lengthharf = request.getParameter("lengthharf");
double area = 0.0;
double lent = 0.0;
try{
double tempValue = Double.valueOf(lengthharf);
area = circleArea(tempValue);
lent = circlLength(tempValue);
}catch(Exception e){
e.printStackTrace();
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<form action="experiment1_2.jsp" method="post">
请输入半径:<input type="text" name="lengthharf">
<input type="submit" name="提交">
</form>
圆周长:<%=lent %>
面积:<%=area %>
</body>
</html>
更多追问追答
追问
运行结果就是可以出现“提交查询内容”,“圆周长”和“面积”字样无法显示,且内容提交后出现错误界面。
追答
看你的jsp的编码格式。这个我都在本地调整过的。
展开全部
<%@page language="java" contentType="text/html;charset=utf-8"%>
<%
class Circle{
private double radius=3;
public double continueLength(){
return Math.PI*2*radius;
}
public double continueArea(){
return Math.PI*radius*radius;
}
}
Circle c=new Circle();
out.println(c.continueLength());
out.println(c.continueArea());
%>
<%
class Circle{
private double radius=3;
public double continueLength(){
return Math.PI*2*radius;
}
public double continueArea(){
return Math.PI*radius*radius;
}
}
Circle c=new Circle();
out.println(c.continueLength());
out.println(c.continueArea());
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询