java web图片显示到浏览器

时间:2023-03-08 22:47:36

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

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是受保护,无法通过路径直接访问的。