Javaweb 之使用 Kaptcha 组件使用验证码
web.xml:
<? xml versión = "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"> <psippision-name> kaptcha </visual <Servlet-name> kaptcha </servlet-name> <ervlet-class> com.google.code.kaptcha.servlet.kaptchaservlet </servlet-class> </servlet> <ervlet-mapping> <ervlet-name> kaptcha </servlet-name> <uRl-pattern> /randomcode.jpg </url-Pattern> </SERVETMAPT <Devene-File-List> <Devene-File> index.html </scede-file> <calle-file> index.htm </welcome-file> <welcome-file> index.jsp </leadde-file> <calleado-file> default.html </a bevieve-file> <cile-file> default.htm </bevie-file> <bevery-file> default.jsp <//welcome-file>
index.jsp:
<%@ page lenguaje = "java" import = "java.util.*" contentType = "text/html; charset = utf-8"%> <%string path = requit.getContextPath (); string basepath = request.getScheme ()+": //"+request.getServerName ()+":"+request.getServerPort ()+path+"/";%> <! DocType html public "-// w3c // dtd html 4.01 transitional // en"> <html> <fead> <fead> <base href = "<%= base = baseT 'index.jsp' Página inicial </title> <meta http-equiv = "pragma" content = "no-cache"> <meta http-equiv = "cache-confontrol" content = "no-cache"> <meta http-equiv = "expira" contenido = "0"> <meta http-equiv = "keywords" contenido "=" key1, keyl key12, WALLWAY2, WALLIN <meta http-equiv = "Descripción" Content = "Esta es mi página"> <!-<Link rel = "Stylesheet" type = "text/css" href = "styles.css">-> </foad> <body> <formule = "check.jsp"> <img src = "randomcode.jpg"> <input type = "text" name "r" type = "enviar"/> </form> </body> </html>
check.jsp:
<%@ página lenguaje = "java" import = "java.util.*" contentType = "text/html; charset = utf-8"%> <%// 检测是否是正确的验证码 string k = (string) session.getAttribute (com.google.code.kaptcha.constants.kaptcha_session_key); Cadena str = request.getParameter ("r"); if (k.equals (str)) out.print ("verdadero"); out.print (""+k+"---"+str);%>结果 :
验证码部分属性修改说明 :
以上就是本文的全部内容 , 希望对大家的学习有所帮助 也希望大家多多支持武林网。 也希望大家多多支持武林网。