我有一个 Spring MVC 应用程序,我正在尝试从 JSP 文件访问 CSS 文件。CSS 依次访问图像文件。
CSS 工作得很好,但没有显示图像。我认为解决图像文件存在问题。
我尝试了绝对寻址和相对寻址来获取图像,但它不起作用。
背景图片:url(“资源/mytheme/images/banner.jpg”);
我还尝试
了 background-image: url("../images/banner.jpg");
谁能帮帮我吗?
我的webapp包如下
webapp
-resouces
-mytheme
-CSS
-template.css
-Images
-banner.jpg
-WEB-INF
-jsp
-login.jsp
-web.xml
-dispatcher-servlet.xml
我的 login.jsp 如下
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<!-- Importing the style sheet for the termplate -->
<link href="<c:url value="/resources/mytheme/css/template.css" />" rel="stylesheet">
</head>
<body>
Hello</body>
</html>
我的CSS文件如下:
#banner {
text-align: center;
background-image: url("resources/mytheme/images/banner.jpg");
background-repeat: no-repeat;
background-size: 1500px 250px;
height: 250px;
}