标签:要求 win lips on() read 设定 显示 arc button
public class Test {
public static void main(String[] args) {
Jedis jedis = new Jedis("192.168.33.128", 6379);
String result = jedis.ping();
System.out.println(result);
jedis.set("name", "刘源");
System.out.println(jedis.get("name"));
jedis.close();
}
}
Exception in thread "main" redis.clients.jedis.exceptions.
JedisConnectionException: java.net.ConnectException:
Connection refused: connect
相关 script 代码:
var t = 120; // 设定倒计时的时间
var interval;
function refer(){
$("#countdown").text("请于" + t + "秒内填写验证码 "); // 显示倒计时
t--; // 计数器递减
if(t <= 0) {
clearInterval(interval);
$("#countdown").text("验证码已失效,请重新发送!");
}
}
$(function(){
$("#sendCode").click(function () {
$.post("/Verify_code/CodeSenderServlet"
, $("#codeform").serialize(), function(data) {
if(data == "true") {
t = 120;
clearInterval(interval);
interval = setInterval("refer()", 1000); // 启动 1 秒定时
} else if (data == "limit") {
clearInterval(interval);
$("#countdown").text("单日发送超过次数!")
}
});
});
$("#verifyCode").click(function () {
$.post("/Verify_code/CodeVerifyServlet"
, $("#codeform").serialize(), function(data) {
if(data == "true") {
$("#result").attr("color", "green");
$("#result").text("验证成功");
clearInterval(interval);
$("#countdown").text("");
} else {
$("#result").attr("color", "red");
$("#result").text("验证失败");
}
});
});
});
相关表单代码:
<form class="navbar-form navbar-left" role="search" id="codeform">
<input type="text" class="form-control"
placeholder="填写手机号" name="phone_no">
<button type="button" class="btn btn-default"
id="sendCode">发送验证码</button><br>
<font id="countdown" color="red"></font>
<br>
<input type="text" class="form-control"
placeholder="填写验证码" name="verify_code">
<button type="button" class="btn btn-default"
id="verifyCode">确定</button>
<font id="result" color="green"></font>
<font id="error" color="red" ></font>
</form>
CodeSenderServlet
protected void doPost(HttpServletRequest request
, HttpServletResponse response) throws ServletException, IOException {
// 获取手机号
String phone_no = request.getParameter("phone_no");
// 获取验证码
String code = getCode(6);
// 拼接键
String codeKey = "verifyCode:" + phone_no + ":code";
// 每个手机号一天只能验 3 次
String countKey = "verifyCode:" + phone_no + ":count";
Jedis jedis = new Jedis("192.168.33.128", 6379);
// 判断发送验证码的次数
String count = jedis.get(countKey);
if(count == null) { // 第 1 次
jedis.setex(countKey, 24*60*60, "1");
} else if(Integer.parseInt(count) < 3) {
jedis.incr(countKey);
} else if(Integer.parseInt(count) >= 3) {
response.getWriter().print("limit");
jedis.close();
return;
}
// 向 redis 中进行存储:以手机号为键,验证码为值
jedis.setex(codeKey, 120, code); // 120s 过期
response.getWriter().print(true);
jedis.close();
}
private String getCode(int length) {
String code = "";
Random random = new Random();
for(int i = 0; i < length; i++) {
int rand = random.nextInt(10);
code += rand;
}
return code;
}
CodeVerifyServlet
protected void doPost(HttpServletRequest request
, HttpServletResponse response) throws ServletException, IOException {
// 获取验证码和手机号
String phone_no = request.getParameter("phone_no");
String verify_code = request.getParameter("verify_code");
// 拼接 key
String codeKey = "verifyCode:" + phone_no + ":code";
// 从 redis 中获取手机号所对应的验证码
Jedis jedis = new Jedis("192.168.33.128", 6379);
String code = jedis.get(codeKey);
if(code.equals(verify_code))
response.getWriter().print(true);
jedis.close();
}
标签:要求 win lips on() read 设定 显示 arc button
原文地址:https://www.cnblogs.com/liujiaqi1101/p/13613196.html