收藏 分销(赏)

javaweb客户端脚本程序.docx

上传人:精*** 文档编号:10138702 上传时间:2025-04-23 格式:DOCX 页数:8 大小:20.48KB
下载 相关 举报
javaweb客户端脚本程序.docx_第1页
第1页 / 共8页
javaweb客户端脚本程序.docx_第2页
第2页 / 共8页
点击查看更多>>
资源描述
实验报告 1、实验目的 通过若干编程题目,加深对session, request response, application对象 2、的理解,掌握其使用方法,初步掌握javascrip客户端验证方法。 2、实验内容和要求 1. 编写login.htm文件,要求用户输入用户名和密码两个文本框,客户端使 用javascrip验证输入不能为空。编写JSP文件judge,jsp判断用户输入。如果用户不等于jsj密码不等于123,则使用JSP动作跳转到fail.ht页面;如果输入 正确,贝U使用response的重定向方法跳转至U success.jsp页面。success.jsp页面 使用即plicatio对象显示用户jsj登录的次数。 2. 编写如下三个文件:a.htm显示一个文本框和一个提交按钮;b.jspt a,htm表单传递的信息存入session变量flag中;c.jsp取出flag变量的值并显示。注意:a.htm的输入可以是中文。 3. 实验步骤 (列出:文件夹结构截图、所有文件的列表、功能说明、运行结果截图) 1. 打开MyEclipse软件,新建一个名为lab02的Web项目,并设置其部署程序为Tomcat 。 2. 在lab02中编写代码。 3. 可以自行练习定义一些css,使页面更加美观。 Lao02 代码 Logi n.html VDOCTYPE html> <html> <head> <meta charset="gbk"> <title服务器简单程序设计</title> </head> <body bgcolor="#CECEFF"> <cen ter> <h1>登陆界面</h1> <form acti on="judge.jsp" method="post”> 用户名:< in put type="text" n ame="n ame"><br> 密码:<input type="password" name="pwd"><br> <input type="submit" name="submit" value="^ <input type="reset" name="reset" valu 重置"> </form></center> </body> </html> Judge.jsp <%@ page language="java" pageEncoding="gbk”%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 "<html><head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title服务器端简单程序设计</title></head> <body bgcolor="#CECEFF"> <center> <h1>登陆界面</h1> <% request.setCharacterEncoding("gbk"); String name=request.getParameter("name"); String pwd=request.getParameter("pwd"); if(name!=null&&pwd!=null&&name.equals("123")&&pwd.equals("123")) {%><jsp:forward page = "success.jsp"/> <% }else{ response.sendRedirect("fail.html"); } %> </center> </body> </html> Success.jsp <%@ page language="java" contentType="text/html; charset=gbk"pageEncoding="gbk"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 "/loose.dtd"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title服务器简单程序设计</title></head> <body bgcolor="#CECEFF"> /loose.dtd"> Transitional//EN" Transitional//EN" <center> <h1 style="green”>登 录成功! </h1> <% request.setCharacterEncoding("GBK"); String name=request.getParameter("name"); String pwd=request.getParameter("pwd"); %> 登录的用户名为:<%=name%><br> 登录的密码为:<%=pwd %><br> <%! Integer yourNumber=new Integer(0); %> <% if(session.isNew()){ Integer number=(Integer)application.getAttribute("Count"); if(number==null) {number=new Integer(1);} else {number=new Integer(number.intValue()+1);} application.setAttribute("Count”, number); yourNumber=(Integer)application.getAttribute("Count"); }%> 欢迎访问本站,您是第<%=yourNumber %> 个访问用户。 </center> </body> </html> Fail.html <!DOCTYPE html> <html> <head> <meta charset="gbk"> <title服务器简单程序设计</title> </head> <body bgcolor="#CECEFF"> <center> <h1 style="green”澄录失败! </h1> <h2>请重新登录,5秒钟后,自动跳转到登录页面! </h2> <% response.setHeader("refresh" "5;url = login.html"); %> </center></body> </html> 截图: o a 登陆界面 用户名; 密码匕 :登录重蛊 登录失败! 诸重新登录,5秒钟后’白动跳转到登录页师! 登录成功! 录的用户名为:1.23录的密码为, 欢迎访I可本站,您是第0个访问用户/ 实验2-2 a. Html v!D0CTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Tra nsiti on al//EN"><html > <head> <title >a.html </title > <meta http-equiv ="keywords" content ="keyword1,keyword2,keyword3” > <meta http-equiv ="description" content ="this is my page" > <meta http-equiv ="content-type" content ="text/html; charset=gbk" > <!--<li nk rel="stylesheet" type="text/css" href="./styles.css">--> </ head> <body> 实验 2-2 <br> <form action ="b.jsp" method ="post" > <input type =text name= "name" ><br> <br> <input type="submit" name ="submit" value ="提交"〉</form > </ body > </html > b. .jsp <%@page language="java" import ="java.util.*" pageEncoding="gbk"%> <% Stri ng path = request.getC on textPath(); Str ing basePath = request.getScheme()+ "://" +request.getServerName()+ ":" +request.getServerPort()+path+ "/";%> <!DOCTYPEHTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"> <html > <head> <base href ="<%=basePath%>"> vmeta http-equiv ="pragma" content ="no-cache" > vmeta http-equiv ="cache-control" content ="no-cache" > <meta http-equiv ="expires" content ="0” > <meta http-equiv ="keywords" content ="keyword1,keyword2,keyword3” > <meta http-equiv ="description" content ="This is my page" > <!-- <li nk rel="stylesheet" type="text/css" href="styles.css"> </ head> <body> 实验 2-2 <br> <%request.setCharacterEncoding( "gbk" );%> <% String submit=request.getParameter( "submit"); String name=request.getParameter( "name"); %> <% if(submit!= null)( session.setAttribute( "flag" ,name); out.println表达信息已经成功保存"); } %> <form action ="c.jsp" method ="post" > <input type="submit" name ="submit" valuep"步"〉 </form > </body> </html > c. Jsp <%@page language="java" import ="java.util.*" pageEncoding="gbk" %> <% Stri ng path = request.getC on textPath(); Str ing basePath = request.getScheme()+ "://" +request.getServerName()+ ":" +request.getServerPort()+path+ "/";%> <!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Tra nsiti on al//EN"> <html > <head> vbase href ="<%=basePath%>"> <title >My JSP 'c.jsp' starting page </title > <meta http-equiv ="pragma" content ="no-cache" > <meta http-equiv ="cache-control" content ="no-cache" > <meta http-equiv ="expires" content ="0” > <meta http-equiv ="keywords" content ="keyword1,keyword2,keyword3” > <meta http-equiv ="description" content ="This is my page" > <!-- <li nk rel="stylesheet" type="text/css" href="styles.css"> > -- </ head> <body> 实验 2-2 <br> <h2> 您输入的信息是:<%=session.getAttribute( "flag") %></h2> </ body > v/html > 提交 My JSP starting pwgm 实验2- 表达信息己经成功保存 下一步 实殛」2 您输入的信息是土 123 4、实验心得
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 通信科技 > 开发语言

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服