首页 > 编程语言 >9.24java wab实现创建新界面验证码

9.24java wab实现创建新界面验证码

时间:2023-09-24 23:22:50浏览次数:35  
标签:java 9.24 wab captcha getElementById var input Login document

<!DOCTYPE html>
<html>
<head>
  <title>User Login</title>
  <style>
    .container {
      width: 300px;
      margin: 0 auto;
      padding: 20px;
      border: 1px solid #ccc;
      text-align: center;
    }
    .input-group {
      margin-bottom: 10px;
    }
    .input-group label {
      display: block;
      margin-bottom: 5px;
    }
    .input-group input {
      width: 100%;
      padding: 5px;
    }
    .input-group img {
      margin-top: 10px;
    }
    .input-group button {
      width: 100%;
      padding: 7px;
      background-color: #4CAF50;
      color: white;
      border: none;
    }
  </style>
  <script>
    function generateCaptcha() {
      var captcha = '';
      var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      var captchaLength = 4;
      for (var i = 0; i < captchaLength; i++) {
        captcha += characters.charAt(Math.floor(Math.random() * characters.length));
      }
      // Display the generated captcha
      document.getElementById('captcha').textContent = captcha;
      // Update the captcha image source with the generated captcha
      document.getElementById('captchaImage').src = 'https://dummyimage.com/150x50/000/fff&text=' + captcha;
    }

    function validateForm(event) {
      event.preventDefault(); // Prevent form submission
      var captchaInput = document.getElementById('captchaInput').value;
      var captchaLabel = document.getElementById('captcha').textContent;
      if (captchaInput.toUpperCase() === captchaLabel.toUpperCase()) {
        // Correct captcha, perform actions for successful login
        alert('Login successful!');
        // Redirect to success page here

        // Clear form data
        document.getElementById('username').value = '';
        document.getElementById('password').value = '';
        document.getElementById('captchaInput').value = '';

        // Generate a new captcha
        generateCaptcha();
      } else {
        // Incorrect captcha, show error message
        alert('Incorrect captcha!');
        // Clear captcha input
        document.getElementById('captchaInput').value = '';
        // Generate a new captcha
        generateCaptcha();
      }
    }
  </script>
</head>
<body onl oad="generateCaptcha()">
  <div class="container">
    <h2>User Login</h2>
    <form action="/login" method="post" onsubmit="validateForm(event)">
      <div class="input-group">
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>
      </div>
      <div class="input-group">
        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required>
      </div>
      <div class="input-group">
        <label for="captcha">Captcha:</label>
        <input type="text" id="captchaInput" name="captcha" required>
        <span id="captcha"></span>
        <img src="" alt="Captcha" id="captchaImage">
        <button type="button" onclick="generateCaptcha()">Refresh</button>
      </div>
      <div class="input-group">
        <button type="submit">Login</button>
      </div>
    </form>
  </div>
</body>
</html>

  

User Login

User Login

Captcha

标签:java,9.24,wab,captcha,getElementById,var,input,Login,document
From: https://www.cnblogs.com/bbbbbeiqu/p/17726927.html

相关文章

  • Java LinkedList与ArrayList源码解析:根本区别和表面区别的详解
    在Java中,LinkedList和ArrayList是两个常见的集合类。它们都实现了List接口,但它们在实现方式上有很大的区别。本篇博客将详细解析LinkedList和ArrayList的源码,解释它们的根本区别和表面区别,并提供详细的代码解释。LinkedList与ArrayList的根本区别:数据结构:LinkedList是基于链表......
  • JAVA语法&包和访问控制
    目录前言一、Java包概述1.包的简介2.包的语法3.包的命名规则4.JDK类库里的包 5.怎么导包二、访问控制1.访问权限修饰符2.Static关键字作用前言在编写 Java一、Java包概述1.包的简介计算机中存放了若干类型的文档,为了管理方便,操作系统采用了树形结构的文件夹形式存放这些文档,并对......
  • Linux第二章文件管理 2023.9.24
    计算机科学与技术1班 学号:20218503姓名:曾庆玲一目录操作首先:cd/cd//切换到根目录1、创建目录mkdirswxy2、查看目录(1)pwd 显示当前所在目录(2)pwd-p显示实际工作目录(3)ls-a查看隐藏的目录与文件(4)ls-l 查看目录与文件的属性3、切换目录(1)cd不加任何路......
  • 简单而经典:Java中的冒泡排序算法详解
    当谈到简单的排序算法时,冒泡排序(BubbleSort)通常是其中之一。虽然它不是最高效的排序算法之一,但它的简单性和易于理解使它成为学习排序算法的良好起点。在本文中,我们将详细介绍Java中的冒泡排序。冒泡排序的基本原理冒泡排序(BubbleSort)是一种简单的排序算法,它通过多次遍历待排序的......
  • Java连接MSSQL2012数据报TLS10 is not accepted by client preferences [TLS13, TLS12
    这一问题好像是因为Java新版本禁用了些老的加密算法引起的,解决方法为修改java.security文件里的配置信息即可。我用的是Java21,在安装目录 Java\jdk-21\conf\security下找到java.security文件,用记事本打开,搜索TLSv1,大概在752行的位置有如下配置信息:jdk.tls.disabledAlgorithm......
  • Java 21 正式发布!新特性专栏继续更起来了~
    就在昨天晚间,Oracle公司宣布Java21正式发布。该版本是继JDK17之后最新的长期支持版本(LTS),将获得至少8年的支持!Java21号称具有数千项性能、稳定性和安全性改进。新的JDK21包括对15项改进的抢先体验,这些增强功能是在OracleCloudWorld2023会议上宣布的,包括支持虚拟线程以......
  • Java语法学习——运算符
    一、基本的算术运算符、+符号做连接符1.基本的算术运算符   为了掌握基本的算术运算符的使用,我们在IDEA里新建一个package(it.com.operator),然后在这下面新建一个Javaclass(OperatorDemo1):packageit.com.operator;publicclassOperatorDemo1{publicstaticvoid......
  • Java课堂
    importjava.awt.*;importjava.awt.event.*;importjava.util.*;publicclassMain{publicstaticdoublemax(double...values){doublelargest=Double.MIN_VALUE;for(doublev:values)if(v>largest)largest=v;......
  • 2023.9.24——每日总结
    学习所花时间(包括上课):0h代码量(行):0行博客量(篇):1篇今天,上午休息,下午休息。我了解到的知识点:休息一天明日计划:1.上课;......
  • 9.24 模拟赛
    时间安排8:00~8:40看题,除a没有会的8:40~9:20写完a9:20~12:00一直看b,想差分约束,然后坐牢总结智力感觉有所下降认真看题面题解An遍dijkstra,然后建图,再跑dijkstraB#include<bits/stdc++.h>#definemod998244353#definelllonglongusingnamespacestd;llC[......