CSS并JS没有在我的应用程序中呈现-
CSS
JS
这是我的Dispatcher.xml-
Dispatcher.xml
<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" 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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config /> <context:component-scan base-package="com.ttnd.springdemo.controller" /> <mvc:resources location="/resources/" mapping="/resources/**" /> <mvc:annotation-driven /> <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> </beans>
以下是我正在使用的页面css/js-
css/js
我以各种方式尝试过,其中一些是-
<link rel="stylesheet" type="text/css" href="css/bootstrap.css"> <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="css/application.css"> <script src="js/application.js"></script> <script src="js/bootstrap.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/jquery.min.js"></script> </head>
要么-
<link rel="stylesheet" type="text/css" href="<spring:url value='resources/css/application.css' />" /> <script src="<spring:url value='resources/js/application.js' />"></script> <script src="<spring:url value='resources/js/jquery.min.js' />"></script>
我的css也有类似的问题,而修复它的方式是....
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/main.css">
如果要对其进行测试以查看是否正在读取css,则可以尝试使用以下URL或类似于http:// localhost:8080 / spring / resources / css /的内容通过浏览器访问css文件 main.css。这应该在浏览器中显示您的CSS文件