jspWord文件下载.docx
《jspWord文件下载.docx》由会员分享,可在线阅读,更多相关《jspWord文件下载.docx(17页珍藏版)》请在冰豆网上搜索。
(2)Image.tag的具体要求
Image.tag使用<
jsp:
doBody/>
处理标记体,并将图像显示在表格的单元中,要求表格每行有三个单元,这三个单元重复显示一幅图像。
解答:
(1)源代码:
putImage:
%@pagecontentType="
text/html;
charset=GB2312"
%>
%@taglibtagdir="
/WEB-INF/tags"
prefix="
pic"
html>
body>
fontsize=2color=blue>
表格每行重复显示一幅图像<
/font>
tableborder=2>
width=80height=60/>
b.jpg"
c.jpg"
/table>
/body>
/html>
Image:
tr>
td>
/td>
/tr>
(2)运行结果:
(alt+printscreen)
(3)运行结果分析:
2.编写一个JSP页面,该JSP页面只负责将学生的姓名和成绩分别存放到链表中,然后将链表传递给Sort.tag,Sort.tag负责按从低到高的顺序显示学生的成绩。
Example3_4.jsp:
%@pageimport="
java.util.*"
show"
bodybgcolor=cyan>
%LinkedListlistName=newLinkedList();
LinkedListlistSroce=newLinkedList();
listName.add("
董文来"
);
listSroce.add(newDouble(95));
张三"
listSroce.add(newDouble(80));
李四"
listSroce.add(newDouble(55));
王五"
listSroce.add(newDouble(88));
赵六"
listSroce.add(newDouble(50));
p>
成绩单
show:
Sorttitle="
姓名"
item="
高等数学"
listName="
%=listName%>
"
listSroce="
%=listSroce%>
Sort.jsp:
%@attributename="
listName"
required="
true"
type="
java.util.LinkedList"
%>
listSroce"
title"
item"
%for(inti=0;
i<
listName.size();
i++){
for(intj=i+1;
j<
j++){
doublea=((Double)listSroce.get(i)).doubleValue();
doubleb=((Double)listSroce.get(j)).doubleValue();
if(b<
a){
Stringtemp=(String)listName.get(i);
Doubler=(Double)listSroce.get(i);
listName.set(i,(String)listName.get(j));
listName.set(j,temp);
listSroce.set(i,(Double)listSroce.get(j));
listSroce.set(j,r);
}
out.print("
tableborder=1>
th>
+title+"
/th>
+item+"
for(intk=0;
k<
k++){
doublescore=(Double)listSroce.get(k);
Stringname=(String)listName.get(k);
if(score<
60){
tdbgcolor=yellow>
+name+"
+score+"
else{
td>
3.编写Tag文件GiveRoot.tag负责求出一元二次方程的根。
JSP页面在调用Tag文件时,使用attribute指令将方程的根传递给Tag文件;
Tag文件GiveRoot.tag使用variable指令返回一元二次方程的根给调用该Tag文件的JSP页面。
userOne.jsp和userTwo.jsp都使用Tag标记调用GiveRoot.tag,返回方程的根。
useOne.jsp将根保留3位小数,并计算方程两个根之和;
useTwo.jsp将根保留5位小数,并计算方程两个根之积。
(1)源代码:
GiveRoot;
%@tagimport="
pageEncoding="
gb2312"
coefficientA"
coefficientB"
coefficientC"
%@variablename-given="
rootOne"
variable-class="
java.lang.Double"
scope="
AT_END"
rootTwo"
%doubledisk,root1,root2;
doublea=Double.parseDouble(coefficientA);
doubleb=Double.parseDouble(coefficientB);
doublec=Double.parseDouble(coefficientC);
disk=b*b-4*a*c;
if((disk>
0)&
&
a!
=0){
root1=(-b+Math.sqrt(disk))/(2*a);
root2=(-b-Math.sqrt(disk))/(2*a);
jspContext.setAttribute("
newDouble(root1));
newDouble(root2));
null);
userOne:
java.text.*"
computer"
computer:
GiveRootcoefficientA="
3"
coefficientB="
6"
coefficientC="
-2"
h4>
方程的根保留3位小数点,并计算两根的和:
%NumberFormatf=NumberFormat.getInstance();
f.setMaximumFractionDigits(3);
if(rootOne!
=null&
rootTwo!
=null){
doubler1=rootOne.doubleValue();
doubler2=rootTwo.doubleValue();
Strings1=f.format(r1);
Strings2=f.format(r2);
out.println("
br>
根1:
+s1);
根2:
+s2);
doublesum=r1+r2;
根1与根2之和:
+sum);
}
方程没有实根"
userTwo;
G