Javaweb 之使用 Kaptcha 组件使用验证码
web.xml:
<؟ XSI: schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id = "webapp_id" الإصدار = "3.0" <Servlet-name> kaptcha </servlet-name> <Servlet-class> com.google.code.kaptcha.servlet.kaptchaservlet </revlet-class> </radlet> <cervlet-mapping> </servlet-maptn> kaptcha </revlet-name> <Url-patern> <lisp-file-list> <ishly-file> index.html </ishified-file> <lisp-file> index.htm </iship-file> <riled-file> index.jsp </elsing-file> </swith-file-list> </web-app>
index.jsp:
<٪@ page language = "java" import = "java.util. request.getScheme ()+": //"+request.getServerName ()+": "index.jsp" صفحة البدء </title> <meta http-equiv = "pragma" content = "no-cache"> <meta http-equiv = "cache-control" content = "no-cacher"> keyworder1 ، keyworder1 ، keyword1 ، keyword1 ، keyword1 ، keyworder1 ، keyword1 ، keyworder1 ، keyworder1 ، keyworder <meta http-equiv = "description" content = "this is is my page"> <!-<link rel = "stylesheet" type = "text/css" href = "styles.css">-> </head> <body> <form action = "check.jsp"> </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) ؛ ٪>: :
: :
以上就是本文的全部内容 , 希望对大家的学习有所帮助 , 也希望大家多多支持武林网。