【发布时间】:2013-10-21 06:47:10
【问题描述】:
当我尝试获取 png 图像的内容类型时,我得到了 null 值
以下是我尝试在servlet 中获取内容类型的方法:
String contentType = getServletContext().getMimeType(image.getName());
我收到contentType = null 和image.getName() 返回png 图像的名称。
我尝试了其他方式来获取相同png图像的内容类型:
String contentType = new MimetypesFileTypeMap().getContentType("imageName.png");
上面的代码给了我contentType = application/octet-stream。
我的问题是为什么我会为同一张图片获得不同的内容类型,我应该怎么做才能获得正确的内容,即image/x-png for .png 类型的图片
【问题讨论】:
-
我没有使用 jdk 7,所以 java.io.Files 选项对我来说很接近。
-
你有没有为你的目的尝试过 apache FileUtils?
-
没有。我为此使用 struts form bean。
-
没关系,您为此使用了哪种数据类型?我建议使用 FormFile。
-
是的,我正在使用相同的 FormFile。
标签: java jakarta-ee servlets struts