我无法从存储在WEB- INF中的JSP访问某些图像和CSS文件。我的Servlet调用了JSP,并且全部加载正常,但是页面无法找到图像和CSS文件。我对这种事情很陌生,希望能提供帮助。我知道过去对此存在一些疑问,我已经尝试过这些建议提出的建议,但是我似乎无法解决。这是JSP的内容(我尝试了一堆不同的方法):
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Title</title> <link rel="stylesheet" type="text/css" href="resources/grid.css"> </head> <body> <!-- Main container --> <div class="container_12"></div> <!-- Foreground container --> <div class="grid_10 prefix_1 suffix_1"> <img src = "/resources/images/Foreground.png"> </div> <!-- Header container --> <div class = "grid 8 prefix_2 suffix_2"> <img src = "${pagecontext.request.contextPath}/resources/images/Header.png"> <p>Test</p> </div> <div class = "clear"></div> <!-- Navigation bar container --> <div class = "grid 8 prefix_2 suffix_2"> <img src = "${pagecontext.request.contextPath}/resources/images/Navbar.png"> </div> </body> </html>
这是我的目录结构:
http://gyazo.com/0a7aea0a44e51e1789c263767e14a40b
您可以使用以下内容找到图像的真实路径。
<!-- Header container --> <div class = "grid 8 prefix_2 suffix_2"> <img src = "<%= application.getRealPath("/resources/images/Header.png") %>"> <p>Test</p> </div>