【问题标题】:WARNING: JSF1091: No mime type could be found for file dynamiccontent警告:JSF1091:找不到文件动态内容的 mime 类型
【发布时间】:2013-02-05 16:59:53
【问题描述】:

我在 eclipse 下收到以下警告:

WARNING: JSF1091: No mime type could be found for file dynamiccontent. To resolve this, add a mime-type mapping to the applications web.xml

这个错误是我发图片的时候引起的

低于 primefaces 合成器:

<p:graphicImage  value="#{bean.image}"/>

Java 豆:

private StreamedContent image;

// Getter
public StreamedContent getImage() {
    try {
        JFreeChart jfreechart = ChartFactory.createPieChart3D("",
                        createDataset(), true, true, false);

        PiePlot3D plot = (PiePlot3D) jfreechart.getPlot();

        File chartFile = new File("dynamichart");
        ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 375, 300);
        chartImage = new DefaultStreamedContent(new FileInputStream(
                        chartFile), "image/png");
        return chartImage;
    } catch (Exception e) {
        e.printStackTrace();
        return new DefaultStreamedContent();
    }
}

// generate data for image
public static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("A",10);
    dataset.setValue("B", 11);
    dataset.setValue("C", 80);
    dataset.setValue("D", 12);
    return dataset;
}

【问题讨论】:

  • 也许你的文件名必须是dynamichart.png(注意文件名的后缀)。
  • 与我们分享更多您的 xhtml 代码。你在哪里使用这个图形图像组件?
  • +1 我也收到了这条消息。我对为什么感兴趣,但后来我从来没有研究过这个,因为它似乎没有任何影响。
  • @maple_shaft,没研究过? This is all you man :)。 This 来自 primefaces 错误跟踪器
  • @kolossus 哈哈哈!!那很好笑!来吧伙计,我应该如何记住我一年前的所作所为? ;-)

标签: jsf primefaces dynamic-content graphicimage


【解决方案1】:

尝试将以下内容添加到您的 web.xml 文件中

<mime-mapping>
    <extension>jsp <!--{or the extension of file}--></extension>
    <mime-type>text/html</mime-type>
  </mime-mapping>

【讨论】:

    【解决方案2】:

    我找到了一种解决方案。

    使用最新版本的 primefaces (3.5)。

    <dependency>  
        <groupId>org.primefaces</groupId>  
        <artifactId>primefaces</artifactId>  
        <version>3.5</version>  
    </dependency> 
    

    但IHM会有不愉快的变化

    【讨论】:

      【解决方案3】:

      我只是想分享我遇到类似问题的经验,我使用mavennetbeanspayara。一旦我收到这个警告:

      警告找不到已记录的文件 fontawesome-webfont.woff 的 mime 类型

      删除此警告的解决方案是将以下代码添加到web.xml

      <mime-mapping>
          <extension>woff</extension>
          <mime-type>application/font-woff</mime-type>
      </mime-mapping>
      

      注意:我对不同的文件有相同的警告,这些文件具有不同的扩展名 (woff, eot, woff2 and ttf)。解决此问题的方法是将&lt;extension&gt; 中的woff 替换为前面提到的扩展之一。

      我希望我的回答有一天能对某人有所帮助。

      PS : 我在page 中找到了解决方案。

      【讨论】:

        【解决方案4】:

        我也收到了针对 http://example.orgjavascript:; 的 JSF1091 警告,使用 Icefaces 而不是 Primefaces。

        变化

        <ice:outputLink onclick="..." value="javascript:;">...</ice:outputLink>
        

        <ice:outputLink onclick="..." value="/some/url">...</ice:outputLink>
        

        消除了关于 javascript:; 的警告。

        变化

        <ice:outputLink value="http://example.org"/>
        

        <a href="http://example.org"/>
        

        为 URL 修复了它。

        【讨论】:

          【解决方案5】:

          虽然我会在一段时间后发布此答案,但它可能对面临此问题的其他开发人员有用。

          为避免上面的恼人警告,请将以下代码添加到您的 web.xml 中:

          <mime-mapping>
          <extension>png</extension>
          <mime-type>image/png</mime-type>
          </mime-mapping>
          

          更多详情请查看:

          http://blog.eisele.net/2011/01/weblogic-10340-oepe-maven-primefaces.html

          【讨论】:

            【解决方案6】:

            对于 Spring Boot 2:

            @Configuration
            public class JsfConfigurationMimeMapper implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
            
                @Override
                public void customize(ConfigurableServletWebServerFactory factory) {
                    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
                    mappings.add("xsd", "text/xml; charset=utf-8");
                    mappings.add("otf", "font/opentype");
                    mappings.add("ico", "image/x-icon");
                    mappings.add("svg", "image/svg+xml");
                    mappings.add("eot", "application/vnd.ms-fontobject");
                    mappings.add("ttf", "application/x-font-ttf");
                    mappings.add("woff", "application/x-font-woff");
                    mappings.add("woff2", "application/x-font-woff2");
                    mappings.add("xhtml", "application/xml");
                    factory.setMimeMappings(mappings);
            
                }
            }
            

            【讨论】:

            • 虽然此代码可能会解决问题,including an explanation 关于如何以及为什么解决问题将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的回答添加解释并说明适用的限制和假设。
            【解决方案7】:

            如果你有 spring 你也可以拥有(我添加了大部分 fa-Icons):

            @Configuration
            public class JsfConfigurationMimeMapper implements EmbeddedServletContainerCustomizer {
            
                 @Override
                 public void customize(ConfigurableEmbeddedServletContainer container) {
                    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
                    mappings.add("xsd", "text/xml; charset=utf-8");
                    mappings.add("otf", "font/opentype");
                    mappings.add("ico", "image/x-icon");
                    mappings.add("svg", "image/svg+xml");
                    mappings.add("eot", "application/vnd.ms-fontobject");
                    mappings.add("ttf", "application/x-font-ttf");
                    mappings.add("woff", "application/x-font-woff");
                    mappings.add("woff2", "application/x-font-woff2");
                    mappings.add("xhtml", "application/xml");
                    container.setMimeMappings(mappings);
                }
            }
            

            【讨论】:

            • 这是当你使用 Spring AND 一个嵌入式容器时,所以你很可能在运行 SpringBoot?
            • 没错,如果您使用的是 SpringBoot,这也是一个解决方案。不使用 web.xml 的人的替代方案。基本上你是在 MimeMappings 上添加你的地图。
            猜你喜欢
            • 1970-01-01
            • 2015-06-06
            • 2013-08-19
            • 2018-09-13
            • 2015-12-20
            • 2013-09-19
            • 2011-01-05
            • 2012-04-24
            • 2019-12-17
            相关资源
            最近更新 更多