编写两个jsp页面a.jsp、b.jsp及一个javabeanCompute.java,a.asp页面提供一个表单,
用户可以通过表单输入矩形的两个变长提交给b.jsp页面,b.jsp条用一个bean去完成计算矩形面积的任务,。b.jsp页面使用getProperty动作标记显示矩形的面...
用户可以通过表单输入矩形的两个变长提交给b.jsp页面,b.jsp条用一个bean去完成计算矩形面积的任务,。b.jsp页面使用getProperty动作标记显示矩形的面积。
答案正确追加积分。 展开
答案正确追加积分。 展开
展开全部
a.jsp如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
<head>
<title>a.jsp</title>
</head>
<body>
<form name="form1" action="b.jsp" method="post">
矩形的长:<input type="text" name="width" size="5" maxlength="5"/><br/>
矩形的宽:<input type="text" name="length" size="5" maxlength="5"/><br/>
<p><input type="submit" name="submit" value="确认"/>
</form>
</body>
</html>
b.jsp如下
<%@ page language="java" import="java.util.*" pageEncoding="gb2312" import="java.lang.*;"%>
<jsp:useBean id="ab" scope="page" class="mypackage.Compute"/>
<html>
<head>
<title>b.jsp</title>
</head>
<body>
<%
double length=Double.valueOf(request.getParameter("length"));
double width=Double.valueOf(request.getParameter("width"));
%>
<%!double area; %>
<%
ab.setLength(length);
ab.setWidth(width);
area=ab.computeArea();
%>
<font size="5" color="red">矩形的面积是:</font>
<%
out.println(area);
%>
</body>
</html>报名为mypackage里面放的类为:Compute代码如下:
package mypackage;
public class Compute {
private double length;
private double width;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double computeArea()
{
return this.length*this.width;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
<head>
<title>a.jsp</title>
</head>
<body>
<form name="form1" action="b.jsp" method="post">
矩形的长:<input type="text" name="width" size="5" maxlength="5"/><br/>
矩形的宽:<input type="text" name="length" size="5" maxlength="5"/><br/>
<p><input type="submit" name="submit" value="确认"/>
</form>
</body>
</html>
b.jsp如下
<%@ page language="java" import="java.util.*" pageEncoding="gb2312" import="java.lang.*;"%>
<jsp:useBean id="ab" scope="page" class="mypackage.Compute"/>
<html>
<head>
<title>b.jsp</title>
</head>
<body>
<%
double length=Double.valueOf(request.getParameter("length"));
double width=Double.valueOf(request.getParameter("width"));
%>
<%!double area; %>
<%
ab.setLength(length);
ab.setWidth(width);
area=ab.computeArea();
%>
<font size="5" color="red">矩形的面积是:</font>
<%
out.println(area);
%>
</body>
</html>报名为mypackage里面放的类为:Compute代码如下:
package mypackage;
public class Compute {
private double length;
private double width;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double computeArea()
{
return this.length*this.width;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |