使用ajax实现验证码
2021-02-12 02:16
标签:head ssi cep extends gets let ltm else password java后台的servlet: 前端的jsp: 1 @WebServlet(value = "/login.love",name = "AjaxLoginServlet")
2 public class AjaxLoginServlet extends HttpServlet {
3
4 @Override
5 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
6 super.doPost(req, resp);
7 }
8
9 @Override
10 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
11
12 ResultMsg rm=new ResultMsg();
13 PrintWriter out=resp.getWriter();
14 Gson gson=new Gson();
15
16 //1 获取前台来的验证码
17 //2 获取session里面的验证码
18 //3 校验
19
20 String vcode=req.getParameter("vcode");
21 String code= (String) req.getSession().getAttribute("code");
22
23 if (null==vcode||null==code){
24 rm.setResult("0002");
25 rm.getMsg("验证码为空");
26
27 out.println(gson.toJson(rm));
28 return;
29 }
30 if (vcode.equalsIgnoreCase(code)){
31 rm.setResult("0000");
32 out.println(gson.toJson(rm));
33 }else {
34 rm.setResult("0001");
35 rm.getMsg("验证码错误");
36 out.println(gson.toJson(rm));
37 }
38
39
40 }
1
2
3
4
17
上一篇:vue错误:vue.runtime.esm.js?0261:619 [Vue warn]: Do not use built-in or reserved HTML elements as compo