<%@ page contentType="text/html;charset=GB2312"%>
<HTML><BODY>
<P>请输入梯形的上底、下底和高
<FORM action=""method=post name=form>
<P>请输入梯形上底a:<INPUT type="text" name="a">
<P>请输入梯形下底b:<INPUT type="text" name=”b”>
<P>请输入梯形高c:<INPUT type="text" name=”c”>
<INPUT TYPE="submit" value="送出" name=submit>
</FORM>
<%--获取用户提交的数据--%>
<% String string_a=request.getParameter("a"),
string_b=request.getParameter("b"),
string_c=request.getParameter("c");
double a=0,b=0,c=0;
%>
<%--判断字符串是否是空对象,如果是空对象就初始化--%>
<% if (string_a=null){
string_a="0";
string_b="0";
string_c="0";
}
%>
<% try{a=Double.valueOf(string_a).doubleValue();
b=Double.valueOf(string_b).doubleValue();
c=Double.valueOf(string_c).doubleValue();
Double area=(a+b)*c/2.0;
out.print("<BR>"+"梯形面积:"+area);
}
catch(NumberFormatException e){
out.print("<BR>"+"请输入数字字符");
}
%>
</BODY></HTML>
2.
main.jsp:
<%@ page contentType="text/html;charset=GB2312" %>
<HTML> <BODY>
<jsp:include page="lader.jsp">
<jsp:param name="a" value="5" />
<jsp:param name="b" value="6" />
<jsp:param name="c" value="10" />
</jsp:include>
</BODY> </HTML>
lader.jsp:
<%@ page contentType="text/html;charset=GB2312" %>
<HTML> <BODY>
<%
String stra=request.getParameter("a");
String strb=request.getParameter("b");
String strc=request.getParameter("c");
Double a=Double.parseDouble(stra);
Double b=Double.parseDouble(strb);
Double c=Double.parseDouble(strc);
double area=(a+b)*c/2;
%>
%>
<P> 梯形面积:<%=area%>
</BODY> </HTML