2

jsp

<img alt="" src='<%=url+"/chartDemo/servlet/ChartDemoServlet"%>'>

我在jsp中有上层代码来使用jfreechart。我已经在窗口机器的tomcat中部署了这个应用程序,它的工作很完美。但是当我在我的linux机器的tomcat中复制相同的文件时,除了图表之外的所有其他jsp内容都会显示出来。

为什么我使用 linux tomcat 运行 Web 应用程序时不显示图表?

当我直接作为 URL 输入 servlet 时,我发现以下异常

java.lang.Error: Probable fatal error:No fonts found.
    sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1088)
    sun.font.FontManager.initialiseDeferredFont(FontManager.java:967)
    sun.font.CompositeFont.doDeferredInitialisation(CompositeFont.java:254)
    sun.font.CompositeFont.getSlotFont(CompositeFont.java:334)
    sun.font.CompositeStrike.getStrikeForSlot(CompositeStrike.java:77)
    sun.font.CompositeStrike.getFontMetrics(CompositeStrike.java:93)
    sun.font.FontDesignMetrics.initMatrixAndMetrics(FontDesignMetrics.java:358)
    sun.font.FontDesignMetrics.<init>(FontDesignMetrics.java:349)
    sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:301)
    sun.java2d.SunGraphics2D.getFontMetrics(SunGraphics2D.java:790)
    org.jfree.text.G2TextMeasurer.getStringWidth(G2TextMeasurer.java:79)
    org.jfree.text.TextUtilities.nextLineBreak(TextUtilities.java:294)
    org.jfree.text.TextUtilities.createTextBlock(TextUtilities.java:235)
    org.jfree.chart.title.TextTitle.arrangeRR(TextTitle.java:628)
    org.jfree.chart.title.TextTitle.arrange(TextTitle.java:497)
    org.jfree.chart.JFreeChart.drawTitle(JFreeChart.java:1316)
    org.jfree.chart.JFreeChart.draw(JFreeChart.java:1204)
    org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1404)
    org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1384)
    org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:183)
    org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:136)
    com.ChartDemoServlet.doPost(ChartDemoServlet.java:170)
    com.ChartDemoServlet.doGet(ChartDemoServlet.java:64)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
4

1 回答 1

1

是的,@Tom 是对的;查找使用的字体。早些时候,没有桌面的 Linux 也没有可用的字体(所谓的无头环境),可通过 GraphicsEnvironment.isHeadless() 和System.getProperty("java.awt.headless");. 您可能只需复制字体并执行 registerFont 即可。

于 2012-05-26T10:44:21.203 回答