Linux系统下Jsp验证码显示不出来, nginx 返回500 解决方法
tomcat日志 localhost.1949-09-15.log 报错信息
1949-09-15 9:13:34 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/wfsb] threw exception [An exception occurred processing JSP page /page/securityCode.jsp at l
ine 24
21: BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
22:
23: // 获取图形上下文
24: Graphics g = image.getGraphics();
25:
26: //生成随机类
27: Random random = new Random();
Stacktrace:] with root cause
java.lang.NullPointerException
at sun.font.FontManager.getDefaultPlatformFont(FontManager.java:3409)
at sun.java2d.SunGraphicsEnvironment$2.run(SunGraphicsEnvironment.java:263)
at java.security.AccessController.doPrivileged(Native Method)
at sun.java2d.SunGraphicsEnvironment.<init>(SunGraphicsEnvironment.java:164)
at sun.awt.X11GraphicsEnvironment.<init>(X11GraphicsEnvironment.java:254)
at sun.reflect.GeneratedConstructorAccessor113.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:534)
at java.lang.Class.newInstance(Class.java:379)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1181)
at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1171)
at org.apache.jsp.pages.securityCode_jsp._jspService(securityCode_jsp.java:91)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.icss.util.XSSFilter.doFilter(XSSFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:143)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
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:76)
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:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:701)
?经过分析,问题出在这行代码:
Graphics g = image.getGraphics();
?
问题的原因是tomcat没有加载java.awt.headless,修改tomcat下的/bin/catalina.sh文件:
- 一、在tomcat/bin/catalina.sh 配置 JAVA_OPTS="-Djava.awt.headless=true"
- 二、找到-Djava.io.tmpdir="$CATALINA_TMPDIR",在这一行的下面加入:
-Djava.awt.headless=true \
需要修改六处
修改后,重启汤姆凯特。
如果还是不行,试试下面这个。 export CATALINA_OPTS="-Djava.awt.headless=true" 修改后,重启汤姆凯特。
如果还是不行,root用户执行命令 runlevel 查看系统的默认启动级别,如果是 : N 3
试试N 5级别。
修改后,重启汤姆凯特。
|