jfinal自带的登录验证码问题

image.pngimage.png

我的项目用了jfinal自带的验证码机制做登录,时不时就会出现这个问题,获取不到验证码回来,是什么问题呢?同样的代码没有修改过,之前是可以用的,但突然有时候上去就不行了,很长一段时间也不行,过个两三天可能又可以用了,有出现过同样问题的朋友吗?


评论区

孤傲苍狼

2019-05-07 14:14

看这个错误是服务端渲染验证码的时候报错了,发出具体的错误日志信息出来看看吧

JFinal

2019-05-07 16:06

@孤傲苍狼 没错,看日志是最好的办法

Aizen

2019-05-10 23:49

@孤傲苍狼 java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment 日志里面第一句就是这个了

bafurei

2019-06-11 21:34

我也遇到了上述问题

bafurei

2019-06-11 21:35

[ERROR]-[Thread: http-nio-9080-exec-6]-[com.jfinal.core.ActionHandler.handle()]: /login/image
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.jfinal.aop.Invocation.invoke(Invocation.java:87)
at com.zcurd.common.interceptor.ErrorInterceptor.intercept(ErrorInterceptor.java:20)
at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
at com.zcurd.common.interceptor.AuthInterceptor.intercept(AuthInterceptor.java:55)
at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)
at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:82)
at com.zcurd.common.handler.ZcurdHandler.handle(ZcurdHandler.java:50)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.zcurd.filter.LoginFilter.doFilter(LoginFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
... 31 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.jfinal.captcha.CaptchaRender
at com.jfinal.render.RenderFactory.getCaptchaRender(RenderFactory.java:171)
at com.jfinal.core.Controller.renderCaptcha(Controller.java:1192)
at com.zcurd.controller.LoginController.image(LoginController.java:32)
... 36 more

JFinal

2019-06-11 21:38

注意看异常这部分:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.jfinal.captcha.CaptchaRender
at com.jfinal.render.RenderFactory.getCaptchaRender(RenderFactory.java:171)

看一下 RenderFactory.java 的 171 行是什么代码,贴出来看一下

Aizen

2019-06-13 09:42

@JFinal public Render getHtmlRender(String htmlText) {
return new HtmlRender(htmlText);
}是这个function

JFinal

2019-06-13 10:13

@Aizen 单步调试进入内部,看看发生了什么

bafurei

2019-06-13 10:44

在本地没有这个问题,在服务器上出现的,ubuntu

JFinal

2019-06-13 11:12

@bafurei 可能是 ubuntu 的少了字体文件,或者是图片 api 支持有问题

试试这个:
render(new com.jfinal.ext.render.CaptchaRender("_jfinal_captcha"));

也可以自己扩展一个 CaptchaRender 出来,然后
render( new MyCaptchaRender());

bafurei

2019-06-13 12:03

JFinal

2019-06-13 12:08

@bafurei jfinal 的 Controller.render(Render render) 方法是开放式结构,可以任意扩展出自己需要的 Render

默认的 CaptchaRender 无法在你的 ubuntu 上使用,找一个第三方的代码扩展出一个 MyCaptchaRender 出来就挺好

NOKIA

2019-12-21 16:04

试了好像不行

xiaodoudou

2020-05-10 21:15

@bafurei 怎么 处理的

听风道长

2020-08-26 22:36

@xiaodoudou https://jfinal.com/share/2249

听风道长

2020-08-26 22:37

@bafurei https://jfinal.com/share/2249

JFinal

2020-10-02 16:35

@all

由于某些 linux 发行版缺少缺少显示设备、键盘或鼠标,无法支持 Graphics、Font、Color、ImageIO、Print、Graphics2D 等类的使用

jfinal 4.9.02 新增一个配置来解决:
me.setToJavaAwtHeadless();

热门反馈

扫码入社