(WordtoPDFConverter-Unregistered)网络软件开发Ⅰ(JavaWeb)实验源代码专业:计算机科学与技术计算机科学与技术20922012年5月目录实验一JavaScript技术应用----------------------------------1实验二JSP技术应用-----------------------------------------4实验三JavaBean技术应用------------------------------------9实验四JSP+JavaBeanWeb项目开发---------------------------12实验五Servlet技术应用及项目开发------------------------(暂无)(WordtoPDFConverter-Unregistered)正文部分:实验源代码由【湪亚非】整理、排版,仅供专业内部学习使用。实验一JavaScript技术应用1.定义一个数组,保存四个字符串:“我是i级标题”,采用循环结构,分别按1、2、3、4级标题格式在web页面上输出这四个字符串。1.jspbody运行结果如下:scriptlanguage=JavaScriptvari=0;for(i=1;i=4;i++){varhead=h+i+我是+i+级标题/h+i+;document.write(head);}/script/body2.编写一个web页面,采用24px、蓝色verdana字体显示绻统时间。2.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=UTF-8%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadbasehref=%=basePath%titleMyJSP'index.jsp'startingpage/titlemetahttp-equiv=pragmacontent=no-cachemetahttp-equiv=cache-controlcontent=no-cachemetahttp-equiv=expirescontent=0metahttp-equiv=keywordscontent=keyword1,keyword2,keyword3metahttp-equiv=descriptioncontent=Thisismypage!--linkrel=stylesheettype=text/csshref=styles.css--scriptlanguage=javascriptfunctionshowtime(){varTimer=newDate();varh=Timer.getHours();varm=Timer.getMinutes();vars=Timer.getSeconds();vard=Timer.getDate();vark=Timer.getMonth();vary=Timer.getYear();k=k+1;varstrShow=日期:+y+-+k+-+d+时间:+h+:+m+:+s;myspan.innerText=strShow;setTimeout(showTime(),1000);}/script/headbodyfontface=verdanasize=24color=#0000ffspanid=myspan时间内容/span/fontscriptshowtime();/script/body/html运行结果如下:3.编写一个web页面,页面上包括用户名和密码输入,提交表单前检查用户名、密码是否输入为空。提交功能暂不实现。3.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=UTF-8%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadbasehref=%=basePath%titleMyJSP'3.jsp'startingpage/titlemetahttp-equiv=pragmacontent=no-cachemetahttp-equiv=cache-controlcontent=no-cachemetahttp-equiv=expirescontent=0metahttp-equiv=keywordscontent=keyword1,keyword2,keyword3metahttp-equiv=descriptioncontent=Thisismypage!--linkrel=stylesheettype=text/csshref=styles.css--scripttype=text/javascriptfunctioncheckForm(form){if(form.username.value==){alert(用户名不能为空!);form.username.focus();returnfalse;}elseif(form.password.value==){alert(密码不能为空!);form.password.focus();returnfalse;}elsereturntrue;}/script/headbody%Stringusername=;Stringpassword=;Cookie[]cookie=request.getCookies();for(inti=0;cookie!=null&&icookie.length;i++){if(username.equals(cookie[i].getName())){username=cookie[i].getValue();}elseif(password.equals(cookie[i].getName())){password=cookie[i].getValue();}}%formname=form_loginaction=success.htmlmethod=postonsubmit=returncheckForm(this)tabletrtd用户名:/tdtdinputtype=textname=username//input/td/trtrtd密 码:/tdtdinputtype=passwordname=password//input/td/trtrtdcolspan=2align=centerinputtype=submitvalue=提交name=BTNsubmit//input/td/tr/table/form/body/html4.编写一个主页面main.html和一个子页面smallwindow.html,主页面上有文本区,还有两个按钮。“打开编辑窗口”按钮用来打开帏窗口,帏窗口通过smallwindow.html子页面可输入用户名和密码,输入的用户名和密码提交以后在主页面文本区显示。主页面上“关闭编辑窗口”按钮可以关闭打开的帏窗口。main.html!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadtitlemain.html/titlemetahttp-equiv=keywordscontent=keyword1,keyword2,keyword3metahttp-equiv=descriptioncontent=thisismypagemetahttp-equiv=content-typecontent=text/html;charset=UTF-8!--linkrel=stylesheettype=text/csshref=./styles.css--scriptlanguage=JavaScriptfunctionopenwindow(){str=window.open(smallwindow.html,smallwindow,toolbar=no,left=500,top=200,menubar=no,width=400,height=400);returnstr}/script/headbodyp用户名:spanid=username/spanp密 码:spanid=password/spanbr/pinputtype=buttonvalue=打开编辑窗口onClick=wyf=openwindow();/inputtype=buttonvalue=关闭编辑窗口onClick=wyf.close();//body/htmlsmallwindow.html!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadtitlesmallwindow.html/titlemetahttp-equiv=keywordscontent=keyword1,keyword2,keyword3metahttp-equiv=descriptioncontent=thisismypagemetahttp-equiv=content-typecontent=text/html;charset=UTF-8!--linkrel=stylesheettype=text/csshref=./styles.css--scripttype=text/javascriptfunctioninputdata(){varwin=window.opener;win.document.getElementById(username).innerHTML=aform.username.value;win.document.getElementById(password).innerHTML=aform.password.value;}/script/headbodyformname=aformaction=#method=postonsubmit=inputdata()tableborder=0trtd用户名:br//tdtdinputtype=textneme=usernameid=login//td/trtrtd密 码:/tdtdinputtype=passwordneme=passwordid=pass/