javaweb课程实验文档

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

第一个实验实验内容:利用HTML和JavaScript技术,设置一个用户信息输入的界面,并检测输入是否为空。设计思路:按照界面要求写好界面,点击确定时对表单依次检查,查看是否有空,如果有空,则弹出对话框,警告用户实验代码:htmlheadtitle设置/titlescripttype=text/javascriptfunctionget_data(){if(userdata.username.value==||userdata.psdone.value==||userdata.psdtwo.value==){alert(账号或密码为空)}else{if(userdata.psdone.value==userdata.psdtwo.value){if(user.name.value==||user.name.value==){alert(姓名或年龄为空)}else{varv1=document.getElementById(sex1);varva1=v1.checked;varv2=document.getElementById(sex2);varva2=v2.checked;if(va1){}elseif(va2){}else{alert(你没有选择性别)}}}else{alert(两次密码不同)}}}/script/headbodydivstyle=margin-left:250px;margin-right:auto;width:600px;height:600px;border:0pxsolid#888;h1style=text-align:center资料设置/h1divstyle=margin-left:250px;margin-right:auto;width:400px;height:600px;border:0pxsolid#888h3style=text-align:center账户信息设置/h3divstyle=height:100px;border:0pxsolid#888formname=userdata账号:inputtype=textname=usernameid=usernamestyle=margin-left:0px;margin-top:5pxvalue='请输入账号'onfocus=javascript:if(this.value=='请输入账号')this.value='';/br/密码:inputtype=passwordname=psdoneid=psdonestyle=margin-top:10px;margin-left:0px/br密码:inputtype=passwordname=psdtwoid=psdtwostyle=margin-top:10px;margin-left:0px//divh3style=text-align:center;margin-top:10px个人信息设置/h3姓名:inputtype=textname=nameid=namestyle=margin-top:5px;margin-left:0px/br/年龄:inputtype=textname=ageid=agestyle=margin-top:2px;margin-left:0px/br/inputtype=radioname=sex1id=sex1value=male男br/inputtype=radioname=sex2id=sex2value=female女inputtype=checkboxname=appleid=apple我喜欢苹果br/inputtype=checkboxname=bananaid=banana我喜欢香蕉divstyle=margin-top:100px;inputtype=buttononclick=get_data()value=确定style=margin-left:180px;/form/div/div/div/body/html运行效果:第二次实验实验内容:小球落地,输入小球的高度和小球下落的时间,求出小球所在的高度,并输出。设计思路:让用户输入小球的高度和下落时间,根据time=Math.sqrt(2.0*H/g);可得到小球一个周期所需要的时间,根据总时间得到期数,再求所在高度实验代码:importjava.util.Scanner;publicclassTest{staticdoubleg=9.8;publicstaticdoubleconclulate(doubleH,doublet){doubletime=Math.sqrt(2.0*H/g);//单程下落时间doubleT=2*time;//下落一周期的时间if(ttime){//下落周期t=T-t;}doubleh1=0.5*g*t*t;//已经下降的高度doubleh=H-h1;//目前的高度returnh;}publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);System.out.println(输入高度);doubleH=s.nextDouble();System.out.println(输入时间);doublet=s.nextDouble();doubleh2=conclulate(H,t);System.out.println(小球目前所处的高度:+h2);s.close();}}运行效果:第三次实验实验内容:javabean,设计一个javabean的类,并对数据进行监听判断数据是否合理实验思路:在javabean类中添加一个监听类对象,当设置分数的把参数传递给监听的对象中的方法,判断是否合理实现代码:Javabean:publicclassJavaBean{privateStringuid;privateStringuname;privateScoreLenterlenter;//监听器publicScoreLentergetLenter(){returnlenter;}publicvoidsetLenter(ScoreLenterlenter){this.lenter=lenter;}publicStringgetUid(){returnuid;}publicvoidsetUid(Stringuid){this.uid=uid;}publicStringgetUname(){returnuname;}publicvoidsetUname(Stringuname){this.uname=uname;}publicStringgetUsex(){returnusex;}publicvoidsetUsex(Stringusex){this.usex=usex;}publicintgetUscore(){returnuscore;}publicvoidsetUscore(intuscore){if(lenter.isHeFa(uscore)){this.uscore=uscore;}else{System.out.println(数据不合法);}}privateStringusex;privateintuscore;}自定义监听类:publicinterfaceScoreLenter{publicbooleanisHeFa(intscore);}测试类:publicclassTestimplementsScoreLenter{publicstaticvoidmain(String[]args){JavaBeanbean=newJavaBean();bean.setLenter(newTest());bean.setUscore(120);}publicbooleanisHeFa(intscore){if(score0||score100){returnfalse;}else{returntrue;}}}运行效果:第四次实验实验内容:设置一个登陆界面,点击登录时把表单提交HttpServlet,判断账号密码是否正确,并把结果返回浏览器设计思路:当数据提交到HttpServlet时,通过request.getParameter()方法得到表单中参数,并判断参数是否合理,如果合理则返回正确,如果不合理返回错误实验代码:登录界面:htmlheadtitle登陆/titlemetahttp-equiv=Content-Languagecontent=gb2312metahttp-equiv=Content-Typecontent=text/html;charset=utf-8//headbodystyle=background-image:url(beijing.jpg)divstyle=width:200px;margin-left:auto;margin-right:auto;color:White;height:200px;margin-top:250pxformaction==post用户名:inputtype=textname=uname/br/密码:inputtype=passwordname=upasswordstyle=margin-top:10px/inputtype=submitvalue=登陆style=margin-top:5pxword-break:break-all/inputtype=buttonvalue=注册†style=word-break:break-all;margin-left:10pxonclick=javascript:window.location.href='set.html'//form/div/body/htmlHttpServlet代码:publicclassLoginServiceextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;publicLoginService(){super();}@OverrideprotectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringusername=request.getParameter(uname);Stringpassword=request.getParameter(upassword);System.out.println(username+username);System.out.println(password+password);if(zhangsan.equals(username)&&123.equals(password)){response.getOutputStream().write(loginsucess.getBytes());}else{response.getOutputStream().write(loginerror.getBytes());}}protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{this.doGet(request,response);}}运行效果:第五次实验实验内容:通过jdbc连接

1 / 13
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功