无法访问Spring MVC应用程序

时间:2015-08-13 12:03:42

标签: css spring-mvc

我有一个Spring MVC应用程序,我试图在CSS文件的background: url(image_path)属性中访问图像。

CSS工作得很好,但图像没有显示出来。我认为解决图像文件存在问题。

我尝试使用绝对寻址和相对寻址来获取图像,但它不起作用。

background-image: url("resources/images/forIndex/bg1.jpg");

我也尝试过:

background-image: url("../images/forIndex/bg1.jpg");

我的 webapp包如下:

enter image description here

的style.css:

#home {
 background:
    url(../images/forIndex/bg1.jpg);
 background-size: cover;
 background-position: center;
 background-repeat: no-repeat;
 background-attachment: fixed;
 height: auto;
 min-height: 710px;
 padding-top: 60px;
 color: #ffffff;
}

#overview-video {
 background: url(resources/images/forIndex/bg2.jpg);
 background-size: cover;
 background-position: center;
 background-repeat: no-repeat;
 background-attachment: scroll;
 text-align: center;
}

MVC-调度-servlet.xml中:

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:default-servlet-handler />
<mvc:annotation-driven />

的web.xml:

<servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mvc-dispatcher-servlet.xml
    /WEB-INF/applicationContext*.xml 
    /WEB-INF/spring-security-servlet.xml</param-value>
</context-param>

<!-- Mapping for images -->
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/images/*</url-pattern>
</servlet-mapping>

任何帮助都将受到高度赞赏。谢谢!!

1 个答案:

答案 0 :(得分:0)

您不需要web.xml中的图像的servlet映射,因为它将通过调度程序servlet。

否则配置似乎没问题。在 www.mysite.com/index.html 等网址上,您应该可以访问以下图片:

background-image: url("resources/images/forIndex/bg1.jpg")