gpt4 book ai didi

javaWeb使用Kaptcha组件生成验证码

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 28 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章javaWeb使用Kaptcha组件生成验证码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

javaWeb之使用Kaptcha组件使用验证码 。

javaWeb使用Kaptcha组件生成验证码

web.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<? xml version = "1.0" encoding = "UTF-8" ?>
< web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://java.sun.com/xml/ns/javaee" xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id = "WebApp_ID" version = "3.0" >
  < display-name >kaptcha</ display-name >
 
  < servlet >
   < servlet-name >kaptcha</ servlet-name >
   < servlet-class >com.google.code.kaptcha.servlet.KaptchaServlet</ servlet-class >
  </ servlet >
  < servlet-mapping >
   < servlet-name >kaptcha</ servlet-name >
   < url-pattern >/randomcode.jpg</ url-pattern >
  </ servlet-mapping >
 
  < welcome-file-list >
   < welcome-file >index.html</ welcome-file >
   < welcome-file >index.htm</ welcome-file >
   < welcome-file >index.jsp</ welcome-file >
   < welcome-file >default.html</ welcome-file >
   < welcome-file >default.htm</ welcome-file >
   < welcome-file >default.jsp</ welcome-file >
  </ welcome-file-list >
</ web-app >

  。

index.jsp

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
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 >My JSP 'index.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" >
   <!--
   <link rel="stylesheet" type="text/css" href="styles.css">
   -->
  </ head >
 
  < body >
    < form action = "check.jsp" >
      < img alt = "" src = "randomcode.jpg" >
      < input type = "text" name = "r" />
      < input type = "submit" />
    </ form >
  </ body >
</ html >

check.jsp

?
1
2
3
4
5
6
7
8
9
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
   //检测是否是正确的验证码
   String k=(String)session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
   String str=request.getParameter("r");
   if(k.equals(str))
     out.print("true");
   out.print("  "+k+"---"+str);
%>

结果:

javaWeb使用Kaptcha组件生成验证码

验证码部分属性修改说明:

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

javaWeb使用Kaptcha组件生成验证码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.

最后此篇关于javaWeb使用Kaptcha组件生成验证码的文章就讲到这里了,如果你想了解更多关于javaWeb使用Kaptcha组件生成验证码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com