首页>代码>jsp滑动拼图极验验证java代码,让用户登录注册更安全,使页面效果更精美>/极验验证/gt-java-sdk-demo/src/com/geetest/sdk/java/web/demo/StartCaptchaServlet.java
package com.geetest.sdk.java.web.demo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.geetest.sdk.java.GeetestLib;


/**
 * 使用Get的方式返回challenge和capthca_id,此方式以实现前后端完全分离的开发模式
 * 用户判断极验服务器是否Down机的示例Servlet,页面生成前置处理
 */
public class StartCaptchaServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		GeetestLib gtSdk = new GeetestLib(GeetestConfig.getGeetest_id(), GeetestConfig.getGeetest_key());

		String resStr = "{}";
		
		//自定义userid
		String userid = "test";

		//进行验证预处理
		int gtServerStatus = gtSdk.preProcess(userid);
		
		//将服务器状态设置到session中
		request.getSession().setAttribute(gtSdk.gtServerStatusSessionKey, gtServerStatus);
		//将userid设置到session中
		request.getSession().setAttribute("userid", userid);
		
		resStr = gtSdk.getResponseStr();

		PrintWriter out = response.getWriter();
		out.println(resStr);

	}
}
最近下载更多
xuhaoa  LV2 2023年11月10日
星予宝藏666  LV6 2023年5月31日
qqwerty  LV3 2022年12月12日
dhvdsgfggfjhfggfyu  LV4 2022年6月1日
1306878374  LV13 2022年2月18日
gus123  LV1 2022年1月17日
不良猫  LV3 2021年12月31日
Start1  LV15 2021年11月3日
nbzhou2013  LV14 2021年10月6日
czr2233  LV9 2021年5月6日
最近浏览更多
black8angel  LV4 2024年10月29日
1516299986  LV9 2024年6月14日
坚持仙蛊 2024年6月12日
暂无贡献等级
3263394665  LV9 2024年3月15日
微信网友_6450287428947968  LV2 2024年2月19日
mayufen 2024年1月4日
暂无贡献等级
ling7314  LV4 2023年12月12日
crrey_wei  LV1 2023年11月27日
Henew168  LV2 2023年11月19日
xuhaoa  LV2 2023年11月10日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友