我收到以下錯誤,同時從ServletContext的資源 XML文檔中添加CSS文件Spring MVC的不能與CSS
線15/WEB-INF /歡迎小服務程序集成的Spring MVC .xml]無效;嵌套的異常是 org.xml.sax.SAXParseException; lineNumber:15; columnNumber:70; cvc-complex-type.2.4.c:匹配通配符是嚴格的,但是對於元素'mvc:resources'可以找到沒有 聲明。
我收到以下錯誤,同時從ServletContext的資源 XML文檔中添加CSS文件Spring MVC的不能與CSS
線15/WEB-INF /歡迎小服務程序集成的Spring MVC .xml]無效;嵌套的異常是 org.xml.sax.SAXParseException; lineNumber:15; columnNumber:70; cvc-complex-type.2.4.c:匹配通配符是嚴格的,但是對於元素'mvc:resources'可以找到沒有 聲明。
使用Spring標籤添加CSS的正確方法:
彈簧的web-config.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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.mkyong.web" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/theme1/"
cache-period="31556926"/>
<mvc:annotation-driven />
</beans>
使用Spring標籤:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html lang="en">
<head>
<spring:url value="/resources/css/main.css" var="mainCss" />
<spring:url value="/resources/js/jquery.1.10.2.min.js" var="jqueryJs" />
<spring:url value="/resources/js/main.js" var="mainJs" />
<link href="${mainCss}" rel="stylesheet" />
<script src="${jqueryJs}"></script>
<script src="${mainJs}"></script>
</head>
<body>
<h1>1. Test CSS</h1>
<h2>2. Test JS</h2>
<div id="msg"></div>
</body>
</html>
如果你的正在使用JSTL
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
<link href="<c:url value="/resources/css/main.css" />" rel="stylesheet">
<script src="<c:url value="/resources/js/jquery.1.10.2.min.js" />"></script>
<script src="<c:url value="/resources/js/main.js" />"></script>
</head>
<body>
<h1>1. Test CSS</h1>
<h2>2. Test JS</h2>
<div id="msg"></div>
</body>
</html>
如需進一步閱讀,請點擊here。
我介紹了所有的網站,我對你給出的示例代碼進行了研究,但仍然出現了我上面提到過的同樣的問題,並且我試着改變了所有的彈簧罐版本。但它仍然沒有發生,請你幫我解決這個問題。它花了我很長時間 –
爲什麼你不嘗試一個乾淨的版本的日食和乾淨的版本的項目。那麼它應該工作。 –
可以請你給我建議更清潔的版本請 –
歡迎來到堆棧溢出請閱讀http://stackoverflow.com/help/how-to-ask然後更新/改進您的問題。 –
如果您仍然需要幫助,請更新您的問題,包括您的xml配置文件。 –