如何用jsp界面与servlet带验证码的登录

本文介绍了如何创建一个包含验证码功能的登录界面,主要涉及jsp和servlet技术。在创建过程中,需要导入特定的jar包,如itcast-tools-1.4.2.jsr、jstl.jar和standard.jar,这些可以在网上找到并下载。通过这些步骤,可以实现一个美观且具有验证功能的登录页面。
摘要由CSDN通过智能技术生成

首先要有优美的登陆界面,这个是在jsp界面中写的

如下代码所示:

login.jsp界面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>用户登陆</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">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script type="text/javascript">
        function change(){
            var imgcode = document.getElementById("imgcode");
            imgcode.src = "<%=path%>/CreateImgCodeServlet?a="+new Date().getTime();
        }
    </script>
  </head>

  <body>

    <h1>用户登录</h1>
    <font color="red">${requestScope.message } </font>
    <form action="${pageContext.request.contextPath}/LoginServlet " method="post">
        <p>
            账号:<input type="text" name="username" value="${cookie.username.value }" />
        </p>
        <p>
            密码:<input type="password" name="password" value="${cookie.password.value }" />
        </p>
        <p>
            验证码:<input type="text" name="imgcode" size="10" />
            <img id="imgcode" alt="验证码" src="${pageContext.request.contextPath }/CreateImgCodeServlet">
            <a href="javascript:change()">换一张</a>
        </p>
        <p>
            <input ty
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值