Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS文件中定义的图像不适用于SpringMVC_Css_Image_Spring_Model View Controller_Resources - Fatal编程技术网

CSS文件中定义的图像不适用于SpringMVC

CSS文件中定义的图像不适用于SpringMVC,css,image,spring,model-view-controller,resources,Css,Image,Spring,Model View Controller,Resources,我使用eclipse创建了一个SpringMVC3.0应用程序。我有一个简单的控制器和JSP视图。我使用了一个CSS文件来指定页面样式。当我打开这个视图时,我发现样式起作用,而图片不起作用。我的目录结构如下所示: webapp webapp-resource webapp-resource-css webapp-resource-css-login.css webapp-resource-image webapp-resource-image-bg.jpg <head>

我使用eclipse创建了一个SpringMVC3.0应用程序。我有一个简单的控制器和JSP视图。我使用了一个CSS文件来指定页面样式。当我打开这个视图时,我发现样式起作用,而图片不起作用。我的目录结构如下所示:

 webapp
 webapp-resource
 webapp-resource-css
 webapp-resource-css-login.css
 webapp-resource-image
 webapp-resource-image-bg.jpg
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/login.css"/>" />
</head>
body {
background: #eeeeee url(../images/bg.jpg) top left repeat;
}
JSP文件如下所示:

 webapp
 webapp-resource
 webapp-resource-css
 webapp-resource-css-login.css
 webapp-resource-image
 webapp-resource-image-bg.jpg
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/login.css"/>" />
</head>
body {
background: #eeeeee url(../images/bg.jpg) top left repeat;
}
配置的资源如下所示:

<mvc:resources mapping="/images/**" location="/resources/images/" />
<mvc:resources mapping="/css/**" location="/resources/css/" />
当我使用HTTP工具查看requset时,我发现图片被标记为text\html

/pangpang/css/login.css;jsessionid=WptcUNivFhWbnYsthGjMLeB8  GET 200 text/css  <link rel="stylesheet">
/pangpang/images/form-bg.png                                 GET 404 text/html background-image
text/html内容类型很可能是因为404响应也有一些text/html内容,在普通资源未找到页面中找不到图像


我认为问题在于:您从form-bg.png查询,但您的文件名为bg.jpg,没有表单前缀

Hi Ralph,谢谢您的帮助。我确认CSS文件中引用的图像存在。我在CSS文件中引用了很多图片。我正在使用“form bg.png”作为示例进行jsut。我已经解决了这个问题。根本原因是我使用了错误的文件夹名“image”,而不是“images”。