首页 > 其他分享 >web实验1

web实验1

时间:2024-06-19 21:21:01浏览次数:12  
标签:web 用户名 登录 用户 实验 background jsp login

1) 编写index.jsp文件,展示某一类物品或知识的介绍,可以是歌曲、人物、名胜古迹等。要求至少有三个条目,用户登录后才能浏览这三个条目的内容。如果用户尚未登录,需要显示用户为“游客”,否则显示用户名。页面下端设置超链接,指向login.jsp。如果用户尚未登录,单击了某一条目的内容,则系统自动转向login.jsp。

2) 编写login.jsp文件,该页面包含一个表单,表单中有两个input标记,分别让用户输入用户名和密码,还有一个登录按钮。当用户单击“登录”后,将表单数据以post的方式提交给check.jsp。

3) 编写check.jsp,该页面使用request对象获取客户端发送过来的用户名和密码,并对用户的合法性进行验证。如果用户输入的用户名和密码不相同,则提示用户登录失败,2秒钟之后自动转向login.jsp页面。如果用户输入的用户名和密码相同,则提示用户登录成功,2秒钟之后转入登录前页面。(提示:登录前页面的记录可以在用户单击的每个网页中,使用session对象的某个属性记录用户访问的当前网页)。

4) 编写三个条目的内容网页。每个网页的上端都需要展示登录的用户名。下端需要“回到首页”的超链接。这三个条目的内容网页只有用户登录后才能浏览。

5) 当用户合法登录后,客户端保留5分钟的Cookie。当用户关闭浏览器后,5分钟之内再次访问时可以免登陆。

6) 将网页源代码和浏览器截图写入实验报告。

三、实验步骤

1)    打开idea软件,新建一个名为javaweb-test3的Web项目,并设置其部署程序为Tomcat。

2)    在javaweb-test3中添加文件,编写代码。

3)    Index.jsp文件代码

4) 
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>主页</title>
</head>
<style>
  body
  {
    background-image: url(/image/gb1.jpg);
    background-size:100% 100% ;
    background-attachment: fixed ;
  }
  table
  {
    border-spacing: 10px 20px;
    border : solid 1px red;
    margin-top:300px;
  }
  .font
  {
    letter-spacing:6px;
  }
</style>
<script>
  function jump(adress, a) {
    if (adress === 's1') {
      if (a == "1") {
        window.location.href = 'login.jsp';
      } else if (a == "2") {
        window.location.href = 's1.jsp';
      }
    } else if (adress === 's2') {
      if (a == "1") {
        window.location.href = 'login.jsp';
      } else if (a == "2") {
        window.location.href = 's2.jsp';
      }
    } else if (adress === 's3') {
      if (a == "1") {
        window.location.href = 'login.jsp';
      } else if (a == "2") {
        window.location.href = 's3.jsp';
      }
    }
  }
</script>
<body class="font">
<%! String a="1";%>
<%! String b="亲爱的游客"; %>
<%
  Cookie[] cookies = request.getCookies();
  if (cookies != null && cookies.length > 0) {
    for (Cookie c : cookies) {
      if (c.getName().equals("username")) {
        b = c.getValue();
      }
      if (c.getName().equals("id")) {
        a = c.getValue();
      }
    }
  }
%>
<marquee scrollAmount="20" direction="left" scrollDelay="90" behavior="alternate" loop="-1" onmouseover="this.stop()"
         onm ouseout="this.start()" hspace="20%">
  <a style="color: red; font-family: 黑体; font-size: 15pt; text-align: center;"><%=b %>,欢迎访问本网站</a>
</marquee>
<div style="text-align: center;">
  <h1>李商隐诗词欣赏</h1>
</div>
<table align="center" valign="middle">
  <tr> <td align="center"><a href="javascript:void(0);" onclick="jump('s1', '<%=a %>')">无题</a></td></tr>
  <tr> <td align="center"><a href="javascript:void(0);" onclick="jump('s2', '<%=a %>')">乐游原</a></td></tr>
  <tr> <td align="center"><a href="javascript:void(0);" onclick="jump('s3', '<%=a %>')">锦瑟</a></td></tr>
  <tr> <td align="center" > <a href="login.jsp">登录</a></td></tr>
</table>
</body>
</html>

5)    Login.jsp文件代码

6)  
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<style>
    body
    {
        background: url(/image/gb1.jpg);
        background-size:100% 100% ;
        background-attachment: fixed

    }
</style>
<script type="text/javascript">
    window.onload = function check( )
    {
        document.getElementById("submit_login").onclick = function()
        {
            var str1 = form1.username.value;
            var str2 = form1.password.value;
            if (str1 == ""||str2 == "") {
                alert("用户名或者密码为空!");
                form1.username.focus();
            }
            return;
        };
    };
</script>
<body>

<form action="check.jsp" method="post" id="form1" name = "form1" onsubmit="">
    <table align="center" valign="middle">
        <tr><td id="top">用户登录 </td></tr>
        <tr>
            <td>用户名:</td>
            <td><input type="text" name="username"  id = "username"value=""> </td>
        </tr>
        <tr>
            <td> 密码:</td>
            <td><input type="password"  name="password" id = "password"> </td>
        </tr>
        <tr>
            <td  colspan="2" align="center"><input type="submit" value="确定" name="submit_login" id="submit_login">
                <input type="reset" > </td>
        </tr>
    </table>
</form>
</body>
</html>

7)    First.jsp文件代码

8)  
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<style>
    body
    {
        background: url(/image/gb1.jpg);
        background-size:100% 100% ;
        background-attachment: fixed

    }
</style>
<script type="text/javascript">
    window.onload = function check( )
    {
        document.getElementById("submit_login").onclick = function()
        {
            var str1 = form1.username.value;
            var str2 = form1.password.value;
            if (str1 == ""||str2 == "") {
                alert("用户名或者密码为空!");
                form1.username.focus();
            }
            return;
        };
    };
</script>
<body>

<form action="check.jsp" method="post" id="form1" name = "form1" onsubmit="">
    <table align="center" valign="middle">
        <tr><td id="top">用户登录 </td></tr>
        <tr>
            <td>用户名:</td>
            <td><input type="text" name="username"  id = "username"value=""> </td>
        </tr>
        <tr>
            <td> 密码:</td>
            <td><input type="password"  name="password" id = "password"> </td>
        </tr>
        <tr>
            <td  colspan="2" align="center"><input type="submit" value="确定" name="submit_login" id="submit_login">
                <input type="reset" > </td>
        </tr>
    </table>
</form>
</body>
</html>

 

标签:web,用户名,登录,用户,实验,background,jsp,login
From: https://www.cnblogs.com/bdsz/p/18257427

相关文章

  • web实验2
    <%@pagecontentType="text/html;charset=UTF-8"language="java"%><html><head>   <title>无题</title></head><bodybackground="/image/gb1.jpg"><divalign="center"style......
  • Linux 中断实验
    Linux中断实验先来回顾一下裸机实验里面中断的处理方法:①、使能中断,初始化相应的寄存器。②、注册中断服务函数,也就是向irqTable数组的指定标号处写入中断服务函数②、中断发生以后进入IRQ中断服务函数,在IRQ中断服务函数在数组irqTable里面查找具体的中断处理函数,找......
  • verilog 设计与综合实验报告(5)
    题目5:序列检测器1、设计方案2、程序代码modulesequential5_detector(inputi_clk, inputi_rst, inputi_seq, outputregout);parameteridle=5'b00000,s1=5'b00001,s2=5'b00010,s3=5'b00100,......
  • 【云服务器介绍】选择指南 腾讯云 阿里云全配置对比 搭建web 个人开发 app 游戏服务器
    ​省流目录:适用于博客建站(2-4G)、个人开发/小型游戏[传奇/我的世界/饥荒](4-8G)、数据分析/大型游戏[幻兽帕鲁/雾锁王国]服务器(16-64G)1.京东云-618专属活动 官方采购季专属活动地址:京东云-618采购季服务器活动专区https://3.cn/20-J4jjX京东云又双叒降价了!活动页大改,增加两......
  • Javaweb
    所花时间: 0.5h代码量(行): 50左右搏客量(篇): 1了解到的知识点:Javaweb备注(其他): 表单标签里面post和get的区别 在刚接触到jsp文件时,我对于里面提交数据的表单标签里面的post和get有点分不清楚<formaction="deletejudge.jsp"metho......
  • 对 websocket 进行封装 (心跳检测 断开重连 发送事件等等 支持断开重连后发送上次发
    代码封装:  //websocketService.jsimport{ref}from"vue";const{DEV,VITE_APP_PUSH_WS}=import.meta.env;const{push_ws}=window.WEB_CONFIG;constbaseWsUrl=DEV?VITE_APP_PUSH_WS:push_ws;classWebSocketService{constructor(ur......
  • webp格式的动图怎么转换成jpeg图片?
    有没有自媒体小伙伴遇到这样的问题呢?找到一张好看的webp格式的图片素材,但是编辑软件却无法打开,显示不支持webp格式的图片。遇到这种情况,你是选择放弃这张素材,重新寻找呢?其实完全没有必要!只要将格式转换成jpeg,就可以继续编辑图片了。方法一:使用图片在线转换工具有很多在线转换工......
  • Spring WebSocket中关于WebSocket配置类的注意事项
    情况1:如果只需要进行简单的通信,不需要消息代理和STOMP协议支持,那么只需要实现WebSocketConfigurer接口注意:实现的接口是WebSocketConfigurer,使用的注解是@EnableWebSocketimportorg.springframework.context.annotation.Configuration;importorg.springframework.web.socke......
  • ETL可视化工具 DataX -- DataX-Web安装 (三)
    引言DataX系列文章:ETL可视化工具DataX–简介(一)ETL可视化工具DataX–安装部署(二)3.1简介DataXWeb是在DataX之上开发的分布式数据同步工具,提供简单易用的操作界面,降低用户使用DataX的学习成本,缩短任务配置时间,避免配置过程中出错。用户可通过页面选......
  • WebService异常: 提供的 URI 方案“https”无效,应为“http”。 参数名: via
    解决如下:把节点 httpsTransport改为 httpTransport原配置:<bindings><customBinding><bindingname="ZWS_CUST"><mtomMessageEncodingmessageVersion="Soap11WSAddressing10"/>......