| | |
| | | package com.yeshi.fanli.controller.validate;
|
| | |
|
| | | import java.io.IOException;
|
| | |
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import javax.servlet.http.HttpSession;
|
| | |
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | |
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.VerifyCodeUtil;
|
| | |
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("admin/new/api/validate")
|
| | | public class ValidateController {
|
| | |
|
| | | @RequestMapping(value = "/imgcode", method = RequestMethod.GET)
|
| | | public void imgCode(HttpServletRequest request, HttpServletResponse response) {
|
| | | response.setHeader("Pragma", "No-cache");
|
| | | response.setHeader("Cache-Control", "no-cache");
|
| | | response.setDateHeader("Expires", 0);
|
| | | response.setContentType("image/jpeg");
|
| | |
|
| | | // 生成随机字串
|
| | | String verifyCode = VerifyCodeUtil.generateVerifyCode(4);
|
| | | // 存入会话session
|
| | | HttpSession session = request.getSession(true);
|
| | | session.setAttribute(Constant.RANDKEY, verifyCode.toLowerCase());
|
| | | // 生成图片
|
| | | int w = 200, h = 80;
|
| | | try {
|
| | | VerifyCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode);
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | package com.yeshi.fanli.controller.validate; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | import javax.servlet.http.Cookie; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.VerifyCodeUtil; |
| | | import org.yeshi.utils.JsonUtil; |
| | | |
| | | |
| | | @Controller |
| | | @RequestMapping("admin/new/api/validate") |
| | | public class ValidateController { |
| | | |
| | | @RequestMapping(value = "/imgcode", method = RequestMethod.GET) |
| | | public void imgCode(HttpServletRequest request, HttpServletResponse response) { |
| | | response.setHeader("Pragma", "No-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | response.setDateHeader("Expires", 0); |
| | | response.setContentType("image/jpeg"); |
| | | |
| | | // 生成随机字串 |
| | | String verifyCode = VerifyCodeUtil.generateVerifyCode(4); |
| | | // 存入会话session |
| | | HttpSession session = request.getSession(); |
| | | session.setAttribute(Constant.RANDKEY, verifyCode.toLowerCase()); |
| | | // 生成图片 |
| | | int w = 200, h = 80; |
| | | try { |
| | | VerifyCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/imgcodeBase64") |
| | | public void imgCodeBase64(HttpServletRequest request, String callback, PrintWriter out,HttpServletResponse response) { |
| | | // 生成随机字串 |
| | | String verifyCode = VerifyCodeUtil.generateVerifyCode(4); |
| | | // 存入会话session |
| | | HttpSession session = request.getSession(); |
| | | System.out.println(session.getId()); |
| | | session.setAttribute(Constant.RANDKEY, verifyCode.toLowerCase()); |
| | | // 生成图片 |
| | | int w = 200, h = 80; |
| | | String base64 = VerifyCodeUtil.getVerifyImagesBase64(w, h, verifyCode); |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(base64))); |
| | | } |
| | | |
| | | } |