当前位置:首页 > JSP程序设计习题解答[1]
public String getArea(double r) { if(r>0)
{
double area=Math.PI*r*r ; return \圆的面积:\ } else
{ return(\不能构成一个圆,无法计算面积\ } } %>
<% out.println(\页面传递过来的半径:\ double r=Double.parseDouble(radius); out.println(getArea(r)); %>
7.编写一个Tag文件GetArea.tag负责求出三角形面积,并使用variable指令返回三角形的面积给调用该Tag文件的JSP页面。JSP页面负责显示Tag文件返回的三角形的面积。JSP在调用Tag文件时,使用attribute指令将三角形三边的长度传递给Tag文件。one.jsp和two.jsp都使用Tag标记调用GetArea.tag。one.jsp将返回三角形的面积保留最多3位小数、two.jsp将返回的三角形面积保留最多6位小数。 答:
one.jsp:
<%@ page contentType=\<%@ page import =\
<%@ taglib tagdir=\
NumberFormat f=NumberFormat.getInstance(); f.setMaximumFractionDigits(3); double result=area.doubleValue(); String str=f.format(result); out.println(str); %>
5
two.jsp:
<%@ page contentType=\<%@ page import =\
<%@ taglib tagdir=\
NumberFormat f=NumberFormat.getInstance(); f.setMaximumFractionDigits(6); double result=area.doubleValue(); String str=f.format(result); out.println(str); %> GetArea.tag:
<%@ attribute name=\<%@ attribute name=\<%@ attribute name=\
<%@ variable name-given=\ <%
double a=Double.parseDouble(sideA); double b=Double.parseDouble(sideB); double c=Double.parseDouble(sideC); if(a+b>c&&a+c>b&&c+b>a) { double p=(a+b+c)/2.0;
double result=Math.sqrt(p*(p-a)*(p-b)*(p-c)) ; jspContext.setAttribute(\ } else
{ jspContext.setAttribute(\ } %>
8.答:
linxi8.jsp:
6
<%@ page contentType=\<%@ taglib tagdir=\
<%@ attribute name=\<%@ attribute name=\<%@ attribute name=\<%@ attribute name=\
习题四
1.答:(C)。
2.答:将获取的字符串用ISO-8859-1进行编码,并将编码存放到一个字节数组中,然后再将这个数组转化为字符串对象。 3.答:
inputString.jsp:
<%@ page contentType=\