CodingAnHour 2016-10-11 05:26 采纳率: 12.5%
浏览 3141
已结题

Spring mvc kaptcha验证码 报错

十月 11, 2016 11:17:57 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [SpringMVC] in context with path [/yiposi] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: com/jhlabs/image/RippleFilter] with root cause
java.lang.ClassNotFoundException: com.jhlabs.image.RippleFilter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at com.google.code.kaptcha.impl.WaterRipple.getDistortedImage(WaterRipple.java:32)
at com.google.code.kaptcha.impl.DefaultKaptcha.createImage(DefaultKaptcha.java:44)
at com.controller.CaptchaController.getCaptchaImage(CaptchaController.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1813)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)


package com.controller;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.Producer;

/**

  • 验证码相关的接口 *
  • @author gaowei.cheng
    */
    @Controller
    @RequestMapping(value = "/captcha")
    public class CaptchaController {

    private static final Log log = LogFactory.getLog(CaptchaController.class);
    @Autowired
    private Producer captchaProducer;

    /**

    • 页面入口
    • @param model
    • @return */ @RequestMapping(value = "/getCaptcha", method = RequestMethod.GET) public String getCaptcha(Model model) { model.addAttribute("timestamp", System.currentTimeMillis()); return "captcha"; }

    /**

    • 生成带验证码的图片
    • @param model
    • @param request
    • @param response
    • @param timestamp
    • @return
    • @throws IOException
      */
      @RequestMapping(value = "/getCaptchaImage", method = RequestMethod.GET)
      public ModelAndView getCaptchaImage(Model model,HttpServletRequest request, HttpServletResponse response,
      @RequestParam(value = "timestamp", required = false) String timestamp) throws IOException {
      if (StringUtils.isEmpty(timestamp)) {
      //System.out.println("没有时间戳\ttimestamp:" + timestamp);
      model.addAttribute("timestamp", System.currentTimeMillis());
      } else {
      //System.out.println("有时间戳\ttimestamp:" + timestamp);
      model.addAttribute("timestamp", timestamp);
      }

      response.setDateHeader("Expires", 0);
      response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
      response.addHeader("Cache-Control", "post-check=0, pre-check=0");
      response.setHeader("Pragma", "no-cache");
      response.setContentType("image/jpeg");
      String capText = captchaProducer.createText();

      request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
      log.info("======生成了一个验证码,内容为:" + capText);
      BufferedImage bi = captchaProducer.createImage(capText);// 这里报错--------------------------------------------------
      ServletOutputStream out = response.getOutputStream();
      ImageIO.write(bi, "jpg", out);
      try {
      out.flush();
      } finally {
      out.close();
      }
      return null;
      }

    /**
    *

    • @param timestamp
    • @param code
    • @param request
    • @return true或fasle,ture表示验证成功,false表示验证失败
      */
      @RequestMapping(value = "/checkCaptcha", method = RequestMethod.POST)
      @ResponseBody
      public String checkCaptcha(@RequestParam(value = "timestamp", required = false) String timestamp, @RequestParam(value = "code", required = false) String code,HttpServletRequest request) {
      boolean returnStr = false;

      String original =(String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
      log.info("======用户输入的验证码:" + code);
      log.info("======正确的验证码:" + original);

      if (!StringUtils.isEmpty(code)) {
      if (code.equalsIgnoreCase(original)) {
      returnStr = true;
      }
      }

      log.info("======验证结果" + returnStr);
      return returnStr + "";

    }
    }


  • 写回答

4条回答 默认 最新

  • devmiao 2016-10-11 05:32
    关注
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境