【发布时间】:2018-05-09 21:08:02
【问题描述】:
我对 Spring mvc 非常陌生,对于这个问题,我在这里找到了很多答案,但没有什么对我有用,请帮助我找出我在这里犯了什么错误。 我在 WebContent>WEB-INF>resources>css>style.css 下创建了一个 css 文件,映射在 spring-servelet.xml 下完成,代码为
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.journaldev.spring" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<!-- Handles HTTP GET requests by efficiently serving up static resources
in the corresponding directory -->
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<mvc:resources mapping="resources/**" location="resources/" cache-period="31556926"/>
</beans:beans>
我已经从 jsp 调用了 css 文件,而 jsp 文件是
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>welcome</title>
<!-- Custom Theme files -->
<link href="<spring:url value='resources/css/style.css' />" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<h1>Hello world!</h1>
<P>The time on the server is ${serverTime}.</p>
</body>
</html>
现在网络已中止错误正在控制台上显示。正如我所说我是这个框架的新手,所以请帮助我而不是给出答案的链接,因为我已经尝试了几乎所有。谢谢
【问题讨论】:
-
你试过
/css/style.css(之前是一个斜线)吗?如果您尝试过单击 cntrl+U 查看源代码并单击 css 链接。正在加载吗? -
是的兄弟,它还没有加载css,当我点击页面源中的链接时,它的显示如下,
-
如果您仍然无法解决此问题,请尝试直接提供路径而不是使用 spring:url 标签`
-
我已经尝试过了,但它不起作用......老兄我会用完整的代码更新我的问题,请看看......
标签: java css spring eclipse model-view-controller