JSP程序设计习题解答[1].. 下载本文

内容发布更新时间 : 2024/5/18 0:58:35星期一 下面是文章的全部内容请认真阅读。

two.jsp:

<%@ page contentType=\<%@ page import =\

<%@ taglib tagdir=\

面积保留6位小数点: <%

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=\

Biaoge.tag:

<%@ attribute name=\<%@ attribute name=\<%@ attribute name=\<%@ attribute name=\ <%=name%> <%=phone%> <%=email%>

习题四

1.答:(C)。

2.答:将获取的字符串用ISO-8859-1进行编码,并将编码存放到一个字节数组中,然后再将这个数组转化为字符串对象。 3.答:

inputString.jsp:

<%@ page contentType=\

7

computer.jsp:

<%@ page contentType=\

<% String textContent=request.getParameter(\ byte b[]=textContent.getBytes(\ textContent=new String(b); %>

字符串:<%=textContent%>的长度:<%=textContent.length()%>

4.答:实现用户的重定向。 5.答:(1) 不相同。(2)相同。(3)可能消失。(4)一定消失。6.答:

lianxi6.jsp:

<%@ page contentType=\ <%

session.setAttribute(\请您猜字母\ char a[]=new char[26]; int m=0;

for(char c='a';c<='z';c++) { a[m]=c; m++; }

int randomIndex=(int)(Math.random()*a.length); char ch=a[randomIndex]; //获取一个英文字母

session.setAttribute(\ session.setAttribute(\%>

访问或刷新该页面可以随机得到一个英文字母.


单击超链接去猜出这个字母: guess.jsp:

8

<%@ page contentType=\<%@ taglib tagdir=\

<% String str=request.getParameter(\ if(str==null) { str=\ }

if(str.length()==0) { str=\ } %>

<% if(message.startsWith(\您猜对了\ {

%>
<% } else {

%>
输入您的猜测:

<% } %> GuessLetter.jsp:

<%@ tag pageEncoding=\

<%@ attribute name=\<%@ variable name-given=\ <% String mess=\

Character ch=(Character)session.getAttribute(\ char realLetter=ch.charValue(); char c=(guessLetter.trim()).charAt(0); if(c<='z'&&c>='a') { 9

if(realLetter==c) {

int n=((Integer)session.getAttribute(\ n=n+1;

session.setAttribute(\ mess=\您猜对了,这是第\次猜测\ }

else if(realLetter

int n=((Integer)session.getAttribute(\ n=n+1;

session.setAttribute(\ mess=\您猜大了,这是第\次猜测\ }

else if(realLetter>c) {

int n=((Integer)session.getAttribute(\ n=n+1;

session.setAttribute(\ mess=\您猜小了,这是第\次猜测\ } } else

{ mess=\请输入a至z之间的英文字母。\ }

jspContext.setAttribute(\%>

习题五

1.答:不能

2.答:调用public long length()方法。 3.答:A和D。

4. 答:RandomAccessFile类既不是输入流类InputStream类的子类,也不是输出流类Outputstream类的子类。想对一个文件进行读写操作时,可以创建一个指向该文件的RandomAccessFile流,这样我们既可以从这个流中读取这个文件的数据,也可以通过这个流给这个文件写入数据。 5. 答:

10