java.lang.InternalError: Can't connect to X11 window server using 'xx.xx.xx.xx:0.0' as the value of the DISPLAY variable.

今天在做JSP图片验证码的时候,在windows下面显示正常,部署到linux下就无法正常显示,报异常如下:

org.apache.jasper.JasperException: An exception occurred processing JSP page /image.jsp at line 21

18: response.setDateHeader("Expires", 0);
19: int width=60, height=20;
20: BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
21: Graphics g = image.getGraphics();
22: Random random = new Random();
23: g.setColor(getRandColor(200,250));
24: g.fillRect(0, 0, width, height);


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

javax.servlet.ServletException: java.lang.InternalError: Can't connect to X11 window server using 'xx.xx.xx.xx:0.0' as the value of the DISPLAY variable.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.image_jsp._jspService(image_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.InternalError: Can't connect to X11 window server using 'xx.xx.xx.xx:0.0' as the value of the DISPLAY variable.
sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
sun.awt.X11GraphicsEnvironment.access$100(X11GraphicsEnvironment.java:52)
sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:155)
java.security.AccessController.doPrivileged(Native Method)
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:131)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1135)
java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1125)
org.apache.jsp.image_jsp._jspService(image_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.

 

 

解决方法:

修改 tomcat/bin/catalina.sh 文件,添加 一行    JAVA_OPTS=-Djava.awt.headless=true 

重启tomcat后,问题解决。

posted @ 2012-05-25 17:37 十年一贱 阅读(...) 评论(...) 编辑 收藏