Java 从config.properties在jsp中显示图像
我需要从config.properties加载图像,并使用cotroller在jsp页面中显示它。我需要简单的解决方案。它是如何工作的? 多谢各位 编辑:Java 从config.properties在jsp中显示图像,java,image,jsp,controller,Java,Image,Jsp,Controller,我需要从config.properties加载图像,并使用cotroller在jsp页面中显示它。我需要简单的解决方案。它是如何工作的? 多谢各位 编辑: 我试过了,但没用。您可以用BASE64格式存储在*.properties文件映像中。通过@Value private String image注释在控制器中获取它,然后将其添加到视图中。在视图中显示接受的图像:遵循此操作,并尝试将图像数据添加到ModelMap中,而不是模型中 Properties prop = new Properties(
我试过了,但没用。您可以用BASE64格式存储在*.properties文件映像中。通过
@Value private String image
注释在控制器中获取它,然后将其添加到视图中。在视图中显示接受的图像:
遵循此操作,并尝试将图像数据添加到ModelMap中,而不是模型中
Properties prop = new Properties();
try {
prop.load(getClass().getClassLoader().getResourceAsStream("config.properties"));
String path = prop.getProperty("filepath") + filename + ".jpg";
BufferedImage image = ImageIO.read(new File(path));
ByteArrayOutputStream byteimage = new ByteArrayOutputStream();
ImageIO.write( image, "jpg", byteimage );
byteimage.flush();
byte[] imageInByte = byteimage.toByteArray();
byteimage.close();
model.addAttribute("image", Base64.getEncoder().encode(imageInByte));
} catch (IOException e) {
e.printStackTrace();
}