kaptcha组件生成验证码
2017-03-09 15:45
369 查看
kaptcha组件生成验证码
先导入kaptcha的jar包
WebRoot---webinf----lib
web.xml 配置------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<servlet>
<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>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
jsp页面
login页
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="check.jsp" method="post">
<img src="randomcode.jpg">
<input type="text" name="login"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
check页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
String k=(String)session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
String strLogin=request.getParameter("login");
if(strLogin.equals(k)){
out.println("true");
}else{
out.println("false");
}
out.println(k+"----"+strLogin);
%>
中文验证码---以后补
算式验证码---以后补
先导入kaptcha的jar包
WebRoot---webinf----lib
web.xml 配置------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<servlet>
<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>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
jsp页面
login页
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="check.jsp" method="post">
<img src="randomcode.jpg">
<input type="text" name="login"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
check页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
String k=(String)session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
String strLogin=request.getParameter("login");
if(strLogin.equals(k)){
out.println("true");
}else{
out.println("false");
}
out.println(k+"----"+strLogin);
%>
中文验证码---以后补
算式验证码---以后补
相关文章推荐
- Java生成验证码(二) 使用Kaptcha组件生成图片验证码
- 谷歌开源组件kaptcha生成验证码
- SpringMVC中使用Kaptcha验证码组件生成比较安全的验证码
- javaWeb使用Kaptcha组件生成验证码
- 无组件生成BMP验证码
- (spring mvc)使用google的kaptcha生成验证码
- 利用谷歌 kaptcha 进行验证码生成
- 使用谷歌kaptcha框架生成验证码的方法
- Kaptcha验证码生成
- 无组件生成BMP验证码
- kaptcha验证码组件实例
- 使用kaptcha生成验证码
- javaWeb之使用Kaptcha组件使用验证码
- 在springmvc项目中使用kaptcha生成验证码
- Sping mvc 环境下使用kaptcha 生成验证码
- 无组件生成验证码-BMP格式
- 无组件生成BMP验证码
- kaptcha 验证码组件使用简介
- kaptcha 验证码组件使用简介
- spring mvc 使用kaptcha生成验证码