My project structure look like this:
Project structure I would like to return a base 64 image took directly from my images folder (in this case, BLUE-CAM1.png).
there is the code where i try to return the image:
@GET @Path("getImage")
public String displayImage()
{
BufferedImage image;
try {
image = ImageIO.read(new File("/images/BLUE-CAM1.png"));
return image.toString();
} catch (IOException e) {
e.printStackTrace();
}
return "nothing";
}
But i got this error:
javax.imageio.IIOException: Can't read input file!
Where should I put the image folder?
Thanks.
我看不到您的项目结构的图像,但是,servlet容器将自动提供META-INF / resources文件夹中存储的资源,因此,如果您将图像打包到此位置的jar文件中(例如META- INF / resources / images / BLUE-CAM1.png),然后从浏览器中访问图像,而无需像上面那样创建rest控制器方法。
http(s)://<host>:<port>/<contextPath>/images/BLUE-CAM1.png
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.