绝对路径,浏览器因为安全策略不给显示;
具体java代码如下:功能如注释所示
/**
* 根据项目绝对路径生成图片、返回相对路径
* @param imageData
* @param cardid
* @return
* @throws Exception
*/
public static String generateImage(String imageData,String filename) throws Exception{
ServletContext sc = ServletActionContext.getServletContext();
String tempImageLocation = "temp";
String absolutePath = sc.getRealPath("/")+tempImageLocation+File.separatorChar+filename+".jpg";
FileUtil.base64StringToPhoto(imageData, absolutePath);
String relativePath = "";
relativePath = sc.getContextPath()+File.separatorChar+tempImageLocation+File.separatorChar+filename+".jpg";
return relativePath;
}
具体action部分语句:
sessionMap.put("<span style="color:#ff0000;">image</span>",FileUtil.generateImage(imageData,filename));
jsp <img></img>部分代码:
<img src="${<span style="color:#ff0000;">image</span>}" style="border: 1px solid #000000; width: 180px; height: 220px; border-image: 1; float: right; margin-right: 150px" />