5

我有一个使用 maven 创建的 Spring 项目。以下是我的目录结构。

在此处输入图像描述

我想在这个项目中添加 css 图像。为此,我在 web-inf 目录中创建了一个资源文件夹,并在其中放置了一个图像。在我的调度程序 servlet xml 中,我添加了 3 行与 mvc 相关的内容。一行在 xmlns:mvc 中,另外 2 行是模式位置的最后 2 行:

http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http:// /www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0 .xsd >

mvc xmlns 和 xsi 位置之前不存在,我添加了它们以便以下行起作用:

<mvc:resources location="/resources/**" mapping="/resources"/>

当我添加上述 3 行时,我的项目不起作用。我得到错误:

description The requested resource is not available.

如果我从 bean 声明中删除 mvc 行并运行不带图像/css 的项目,则项目运行。

谁能帮我这个?如果上述方法不是在spring mvc项目中添加css和图片的方法,请指出正确的方法。

非常感谢!

4

2 回答 2

5

你需要一个小小的改变,即。

<mvc:resources mapping="/resources/**" location="/resources/" />

加上根据标准的maven项目创建一个新文件夹并将你的资源放在这个

src/main/resources
于 2013-06-15T14:26:35.063 回答
0
   webapp/resources/css 
   <head>
  <link href="<c:url value="/resources/css/commoncss.css" />" rel="stylesheet">
  </head>  

如果不在 webapp 中查找资源文件夹,则在 webapp 中手动创建文件夹作为资源/css 文件夹,将您的 css 文件放入 css 文件夹中。

于 2019-11-21T04:20:30.943 回答