Javaweb b 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/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"> kaptcha </display-name> <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> <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> default.htm </welcome-file> default.jsp <jsp> </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 wentritional // en"> <html> <head href = <%= basepathent> "> 'index.jsp'시작 페이지 </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 = "keyword" <meta http-equiv = "description"content = "this my page"> <!-<link rel = "stylesheet"type = "text/css"href = "styles.css">-> </head> <form action = "check.jsp"> <img src = "randomcode.jpg"> 타입 = "제출"/> </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); 문자열 str = request.getParameter ( "r"); if (k.equals (str)) out.print ( "true"); out.print ( ""+k+"---"+str);%>
结果 :
验证码部分属性修改说明 :
以上就是本文的全部内容 以上就是本文的全部内容, 希望对大家的学习有所帮助, 也希望大家多多支持武林网。