Javaweb 之使用 Kaptcha 组件使用验证码
web.xml:
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <web-app xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns = "http://java.sun.com/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 </servlet-lass> </servlet> <servlet-mapping> <servlet-name> <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>
index.jsp:
<%@ page language = "java" import = "java.util.*" contentType = "text/html; charset = utf-8"%> <%String Path = request.getContextPath (); string basepath = request.getScheme ()+": //" html public "-// w3c // dtd html 4.01 transitional // en"> <html> <head> <base href = "<%= basepath%>"> <title> jsp 'index.jsp' ของฉัน http-equiv = "cache-control" content = "no-cache"> <meta http-equiv = "Expires" content = "0"> <meta http-equiv = "คำหลัก" content = "keyword1, คำหลัก 2, คำหลัก type = "text/css" href = "styles.css"> -> </head> <body> <form action = "check.jsp"> <img src = "onaderCode.jpg"> <อินพุต type = "text" name = "r"/> <อินพุต type = "ส่ง"/>
ตรวจสอบ. jsp:
<%@ page language = "java" import = "java.util.*" contentType = "text/html; charset = utf-8"%> <%// 检测是否是正确的验证码สตริง k = (สตริง) เซสชัน. string str = request.getParameter ("r"); if (k.equals (str)) out.print ("true"); out.print (""+k+"---"+str);%>结果:
验证码部分属性修改说明:
以上就是本文的全部内容, 希望对大家的学习有所帮助, 也希望大家多多支持武林网。