无法在SpringMVC4(eclipse)中加载本地css
我想我的配置是正确的,但我无法加载css。这似乎永远不会奏效。我用谷歌搜索了大部分结果,但没有一个对我有用。我不知道我哪里做错了 pom.xml无法在SpringMVC4(eclipse)中加载本地css,css,xml,spring,servlets,model-view-controller,Css,Xml,Spring,Servlets,Model View Controller,我想我的配置是正确的,但我无法加载css。这似乎永远不会奏效。我用谷歌搜索了大部分结果,但没有一个对我有用。我不知道我哪里做错了 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.alias</groupId>
<artifactId>YayaWine</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>YayaWine Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>4.0.1.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<finalName>YayaWine</finalName>
</build>
</project>
4.0.0
com.alias
雅雅葡萄酒
战争
0.0.1-快照
YayaWine Maven网络应用程序
http://maven.apache.org
4.0.1.1发布
朱尼特
朱尼特
3.8.1
测验
org.springframework
弹簧芯
${spring.version}
org.springframework
弹簧网
${spring.version}
org.springframework
SpringWebMVC
${spring.version}
javax.servlet
jstl
1.2
雅雅葡萄酒
web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
s
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Web应用程序创建的原型
调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
/
上下文配置位置
/WEB-INF/dispatcher-servlet.xml
s
org.springframework.web.context.ContextLoaderListener
dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="wine.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:annotation-driven />
<mvc:resources mapping="/css/**" location="/resources/css" />
<mvc:default-servlet-handler />
</beans>
/WEB-INF/views/
.jsp
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head lang="lang">
<meta name="viewpoint" content="width=device-width, initial-scale=1">
<link href="/css/bootstrap.css " rel="stylesheet" >
<link href="/css/test.css " rel="stylesheet" >
<title>hello</title>
</head>
<body>
<h2>Hello World!</h2>
</body>
</html>
你好
你好,世界!
在jsp
中更新您的链接
标记,如下所示
<link href="${pageContext.request.contextPath}/css/bootstrap.css" rel="stylesheet" >
<link href="${pageContext.request.contextPath}/css/test.css" rel="stylesheet" >
您是否尝试使用浏览器的开发工具并检查了状态?您的css文件夹在项目结构中的位置?我将我的css放在resources/css下