一、后台方法
@RequestMapping("/getImageIo")
public String getImage(HttpServletRequest request,
HttpServletResponse response, ModelMap model) throws Exception{
String fileName = request.getParameter("fileName");
String fileUrl = PATH;//图片存放路径参数:/weblogic/qywx/
// String fileUrl = "/weblogic/shoppingMall";
// PatternUtil.validNum(fileName, "100", "10");
// String patternRole = "^\\d{5,100}.(jpg)|(png)|(jpeg)$";
// if (!Pattern.matches(patternRole, fileName)) {
// return null;
// }
FileInputStream fis = null;
OutputStream toClient = null;
try {
fis = new FileInputStream(fileUrl + fileName);
int i = fis.available();
byte data[] = new byte[i];
fis.read(data);
response.setContentType("image/jpg");
toClient = response.getOutputStream();
toClient.write(data);
toClient.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
toClient.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
二、前端HTML路径书写格式
参数:
ShowImageURL:http://10.96.97.21:8082/workweixin/
imageName1:图片名称
书写格式
var image1 = "[[${ShowImageURL}]]/getImageIo?fileName=[[${imageName1}]]" + ".png";