java web图片显示到浏览器

今天研究了一下午,图片显示问题。


jsp中获取绝对路径的方法:
String contextPath = request.getContextPath();
String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() + contextPath;
然后<img src="<%=path%>/.../scene.jpg" ALT=""/> 


有一点一定要记住!image,css文件夹千万不要放到WEB-INF文件下,因为WEB项目,WEB-INF是受保护,无法通过路径直接访问的。


原文地址:https://www.cnblogs.com/rixiang/p/5323841.html