首页 文章

将CSS和图像链接到Spring MVC maven Projcet

提问于
浏览
4

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

enter image description here

我想将css图像添加到此项目中 . 为此,我在web-inf目录中创建了一个资源文件夹,并在那里放置了一个图像 . 对于我的调度程序servlet xml,我添加了3行,与mvc有关 . 一行在xmlns:mvc中,另外两行是架构位置中的最后两行:

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行并运行项目w / o images / css项目运行 .

谁能帮我这个?如果上述方法不是将css和图像添加到spring mvc项目的方法,请指出正确的方法 .

非常感谢!

1 回答

  • 2

    你需要一个小小的改变即 .

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

    加上根据标准maven项目创建一个新文件夹并将您的资源放入此中

    src/main/resources
    

相关问题