Spring MVC 4.1.5 使用 CSS 中的图像资源来设置视图"jsp"样式



//css样式的base.jsp似乎找不到资源图片的位置:background image:url("/resources/gearsCon_logo.png");tiles-servlet.xml配置或web.xml中我错了吗。?servlet中的正确配置应该是什么。??顺便说一句,图像在"src/resources/image.jpg">

**web.xml**
######################### 
enter code here
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/ns/javaee/web-app_4_1.xsd"
xmlns:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/ns/javaee/web-app_4_1.xsd"
id="WebApp_ID" version="4.1">
<display-name>tiles</display-name>
<servlet>
<servlet-name>tiles</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>    
</servlet>   
<servlet-mapping>
<servlet-name>tiles</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>
home.htm
</welcome-file>
</welcome-file-list>
</web-app>
**tiles-servlet.xml**
#################################
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc= "http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"
> 
<context:component-scan base-package="com.test.controller"/>  
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>
**base.jsp**
#########################
this is the jsp file which I embedded my css <style/>
#logo {  
background-image: url("/resources/gearsIcon_logo.png"); 
background-size: 80px 60px;
background-repeat: no-repeat;
width: 100px;
height: 100px;
margin-top: -81px;
}

//它无法映射/找到资源图像的位置:background image:url("/resources/gearsCon_logo.png");tiles-servlet.xml配置或web.xml中我错了吗。?servlet中的正确配置应该是什么。??

很抱歉很晚才回复这篇文章,我已经得到了解决方案。

tiles servlet.xml中,我放了以下内容:

<mvc:resources mapping="/resources/**" location="/resources/"
cache-period="31556926" />

因此:资源文件夹位于/Webcotent/resources 下

在我的header.jsp中,我添加了以下内容:

<spring:url     value="/resources/img/gearsIcon_logo.png" var="img">  
</spring:url>

这解决了我的痛苦。干杯

最新更新