项目前端界面要读取本地D盘下yueyang图片,后台不用流,前端img标签如何写路径?我试过在Tomcat里面配置映射但是没用,不知道是我配置错了还是什么原因,请问配置映射这种方法行得通的吗?下面贴上配置的图片
/**
* 地址映射
* @param request
* @param response
* @param path
* @param fileName
* @throws IOException
*/
@RequestMapping("/MediaLibrary/{path}/{fileName:.+}")
public void download( HttpServletRequest request,
HttpServletResponse response,@PathVariable String path,@PathVariable String fileName) throws IOException {
String filePath = UploadConfig.getExtProperties().getUploadVideoDefaultPath() + "/MediaLibrary/" + path + "/" + fileName;
String fileExtName = fileName.substring(fileName.lastIndexOf(".") + 1);
if(fileExtName.equalsIgnoreCase("mp4"))
{
response.setContentType("video/mp4");
}
else if(fileExtName.equalsIgnoreCase("jpg")||fileExtName.equalsIgnoreCase("png")||fileExtName.equalsIgnoreCase("gif")||fileExtName.equalsIgnoreCase("jpeg"))
{
response.setContentType("image/jpeg");
}
else{
response.setContentType("text/html");
}
FileInputStream st = null;
StreamUtils.copy(st = new FileInputStream(new File(filePath)), response.getOutputStream());
st.close();
}
UploadConfig.getExtProperties().getUploadVideoDefaultPath()改成你的绝对路径前缀,比如D:/,然后可以把 "/MediaLibrary/"改成你的yueyang,我配置两个/{path}/{fileName:.+}是因为我后面有一个文件夹,文件夹下面才是文件,这两层目录都不确定,你的话如果文件直接存在yueyang下,就用{fileName:.+}就可以,然后方法里的参数也改成对应的。这个不用在Tomcat配置虚拟路径。
1、前提是不知道你的需求为什么这么奇葩,为什么要读取本地的图片。
2、你可以把图片存到服务器,然后就可以了。
3、你看看控制台输出这么多404,难道你没有什么想法吗?
4、你把图片先放到你的项目web下的yueyanggridradar/下,然后再试试。