您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > web WEB JSP实验报告书
实验1网页程序设计-JavaScript一、实验目的1.掌握JavaScript技术,基本掌握JavaScript的开发技巧;2.利用文本编辑器建立JavaScript脚本语言进行简单编程。二、实验要求:1.根据以下实验内容书写实验准备报告。2.独立完成实验。三、实验内容1.显示一个动态的时钟在文本编辑器“记事本”中输入如下代码程序,请仔细阅读下列程序语句,理解每条语句的作用。源程序清单如下:htmlheadscriptlanguage=javascriptvartimer=nullfunctionstop(){clearTimeout(timer)}functionstart(){vartime=newDate()varhours=time.getHours()varminutes=time.getMinutes()minutes=((minutes10)?0:)+minutesvarseconds=time.getSeconds()seconds=((seconds10)?0:)+secondsvarclock=hours+:+minutes+:+secondsdocument.forms[0].display.value=clocktimer=setTimeout(start(),1000)}/script/headbodyonLoad=start()onUnload=stop()form现在是北京时间:inputtype=textname=displaysize=20/form/body/html运行结果:2.事件驱动和事件处理在文本编辑器“记事本”中输入如下代码程序,请仔细阅读下列程序语句,理解每条语句的作用。源程序清单如下:htmlheadscriptlanguage=javascriptfunctionmyfunction(){alert(HELLO)}/script/headbodyforminputtype=buttononClick=myfunction()value=Callfunction/formpBypressingthebutton,afunctionwillbecalled.Thefunctionwillalertamessage./p/body/html运行结果:3.JavaScript表单校验编写程序register.html,做一个如下图所示的用户注册界面,要求对用户填写的部分进行合法性检验。源程序清单如下:!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//EN%@pagecontentType=text/htmlpageEncoding=gb2312%htmlheadmetahttp-equiv=Content-Typecontent=text/html;charset=gb2312title用户登录/titlescriptlanguage=javascriptfunctionon_sumbit(){if(form1.username.value==){alert(用户名不能为空请输入用户名!);form1.username.focus();returnfalse;}if(form1.userpassword.value==){alert(用户密码不能为空请输入密码!);form1.username.focus();returnfalse;}if(form1.userpassword.value!=&&form1.username.value!=){alert(欢迎);}}/script/headbodyformmethod=POSTname=form1onsubmit=returnon_submit()用户登录:br请输入用户名:inputtype=textname=usernamesize=20br请输入密码 :inputtype=passwordname=userpasswordsize=20brinputtype=buttonvalue=提交onclick=on_sumbit()inputtype=resetvalue=全部重写/form/body/html实验2Request与Response对象的应用一、实验目的1.掌握JSP的Request与Response隐式对象的用法,基本掌握JSP的开发技巧。2.在JDK和MyEclipse环境下,完成下列实验。二、实验要求1.独立完成实验。2.书写实验报告书。三、实验内容编写程序实现一个单选小测试。在test.jsp页面显示问题,并将答案提交至answer.jsp进行判断,如果回答正确,则将页面转至yes.jsp;否则,转至no.jsp。1.打开MyEclipse,新建WebProject,命名TestJSP;2.在WebRoot文件夹下,新建jsp文件(test.jsp、answer.jsp、yes.jsp和no.jsp)3.点击进行部署,部署到tomcat上;4.打开Servers选项卡,在下图中右键启动Tomcat,在浏览器中输入为新建web项目名称test.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=gb2312%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadbasehref=%=basePath%titleMyJSP'test.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--/headbody北京奥运会的开幕日期是:brFormaction=answer.jspMETHOD=postNAME=formINPUTTYPE=radioNAME=itemVALUE=1八月六日INPUTTYPE=radioNAME=itemVALUE=2八月八日INPUTTYPE=radioNAME=itemVALUE=3八月九日INPUTTYPE=radioNAME=itemVALUE=4八月十日brINPUTTYPE=submitNAME=ENTERVALUE=提交答案/Form/body/htmlanswer.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=gb2312%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadbasehref=%=basePath%titleMyJSP'answer.jsp'startingpage/title/headbody%Stringstr=request.getParameter(item);out.println(str);if(str.equals(2))response.sendRedirect(yes.jsp);elseresponse.sendRedirect(no.jsp);%/body/htmlyes.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=gb2312%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//EN%@pagecontentType=text/html;charset=GB2312%htmlheadbasehref=%=basePath%titleMyJSP'yes.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--/headbody恭喜您,答对了!/body/htmlno.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=gb2312%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadbasehref=%=basePath%titleMyJSP'no.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--/hea
本文标题:web WEB JSP实验报告书
链接地址:https://www.777doc.com/doc-3368595 .html