gpt4 book ai didi

java - 无法在spring mvc中使用css/js等资源

转载 作者:行者123 更新时间:2023-12-01 21:53:33 25 4
gpt4 key购买 nike

CSSJS 未在我的应用程序中渲染-

这是我的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-

的页面

我通过各种方式尝试过,其中一些是-

<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,您可以尝试通过浏览器访问CSS文件,使用以下网址或类似http://localhost:8080/spring/resources/css/main.css的内容。这应该会在浏览器中显示您的 css 文件

关于java - 无法在spring mvc中使用css/js等资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34786182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com