Javaweb 之使用 Kaptcha 组件使用验证码
Web.xml:
<? Xml Version = "1.0" encoding = "utf-8"?> <web-app xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns = "http://java.sun.com/xmlns =" http://java.com/xmlns = "http://java.com/xmlns = XSI: schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" ID = "webapp_id" Versi = "3.0"> <Display-2> <servlet-name> Kaptcha </servlet-name> <servlet-class> com.google.code.kaptcha.servlet.kaptchaservlet </servlet-class> </servlet> <servlet-Mapping> <servlet-name> Kaptcha </servlet-name> <rerl-pattern> /randomcode. <creendak-file-list> <creendak-file> index.html </celcome-file> <creendak-file> index.htm </celcome-file> <creendak-file> index.jsp </celcome-file> <creendak-filtm> default.html </welcome-file> <creend-file> DEFAULT.htm </Welcome-File> </Welcome-File> <creend-file> Default.htm </Welcome-File> </Welcome-File> </celcome-file-list> </web-app>
index.jsp:
<%@ page language = "java" import = "java.util.*" contentType = "text/html; charset = utf-8"%> <%string path = request.getContextPath (); String Basepath = quxCheme ()+": //"+request.getServername () (); Html public "-// w3c // dtd html 4.01 transisi // en"> <html> <adept> <base href = "<%= basepath%>"> <itement> jsp 'index.jsp' start page </title> <meta http-quiv = "no" conten = "no-cache" <Meta http-content = "pragma =" no "no-cache" <Meta http-quiv = "pragmma =" no "no" no-cache " http-equiv = "cache-control" content = "no-cache"> <meta http-equiv = "kedaluwarsa" konten = "0"> <meta http-equiv = "kata kunci" konten = "kata kunci1, kata kunci2, koki"> <meta http http-equiv = "koki" ini = "ini" type = "text/css" href = "styles.css"> -> </head> <body> <Form Action = "check.jsp"> <img src = "randomCode.jpg"> <input type = "Text" name = "r"/> <input type = "kirim"/</bentuk> </body> </htm
check.jsp:
<%@ halaman bahasa = "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);%>结果 :
验证码部分属性修改说明 :
以上就是本文的全部内容 , 希望对大家的学习有所帮助 , 也希望大家多多支持武林网。