手机
当前位置:查字典教程网 >编程开发 >Java >javaWeb使用Kaptcha组件生成验证码
javaWeb使用Kaptcha组件生成验证码
摘要:javaWeb之使用Kaptcha组件使用验证码web.xml:kaptchakaptchacom.google.code.kaptcha....

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

javaWeb使用Kaptcha组件生成验证码1

web.xml:

<"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:

<%@ 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:

<%@ 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组件生成验证码2

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

javaWeb使用Kaptcha组件生成验证码3

javaWeb使用Kaptcha组件生成验证码4

javaWeb使用Kaptcha组件生成验证码5

javaWeb使用Kaptcha组件生成验证码6

javaWeb使用Kaptcha组件生成验证码7

javaWeb使用Kaptcha组件生成验证码8

javaWeb使用Kaptcha组件生成验证码9

javaWeb使用Kaptcha组件生成验证码10

javaWeb使用Kaptcha组件生成验证码11

javaWeb使用Kaptcha组件生成验证码12

javaWeb使用Kaptcha组件生成验证码13

javaWeb使用Kaptcha组件生成验证码14

javaWeb使用Kaptcha组件生成验证码15

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持查字典教程网。

【javaWeb使用Kaptcha组件生成验证码】相关文章:

java线程之join方法的使用介绍

java switch语句使用注意的四大细节

java使用dom4j操作xml示例代码

java 学习笔记(入门篇)_java的安装与配置

java使用Memcached简单教程

java中File类的使用方法

java生成压缩文件示例代码

jfinal添加jcaptcha验证码实现方法

java使用命令行打包JAR

java基本教程之线程让步 java多线程教程

精品推荐
分类导航