【发布时间】:2018-05-08 12:09:43
【问题描述】:
我正在通过 NetBeans 使用 spring 4.0.1 框架和 glassfish 服务器创建 Web 应用程序,并且在访问它的 css 和 js 文件时遇到问题,该文件位于项目结构中,如下所示
如您所见,我已将 Web-INF 和资源放在同一级别(在 Web-INF 文件夹之外),并且在尝试了许多关于堆栈溢出的类似问题的解决方案之后(无法分享我的所有发现在这里),没有什么对我有用。
以下是我在以下文件中所做的一些更改
Dispatcher-servlet.xml
<context:component-scan base-package="com.onlinetutorialspoint.controllers" />
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**"
location="resources/"
cache-period="31556926" />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
Login.jsp(在给定的 jsp 中使用了三种方式访问 CSS,但对我没有任何作用)
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/layoutlocal.css" />
<link rel="stylesheet" href="/resources/css/layoutlocal.css" />
<link href="<c:url value="/resources/css/layoutlocal.css" />" rel="stylesheet" type="text/css" />
即使在控制器和其他功能正常运行后,我也无法访问任何 CSS 或 JS 文件.. 但是如果我在浏览器中打开以下 URL http://localhost:8080/SampleSpringApplication/resources/css/loginpagestyle.css,它会显示我的默认页面而不是 CSS 页面。
【问题讨论】:
-
不确定它是否会起作用,但请尝试将文件结构中的
resources/css更改为resources/static/css(因此添加一个额外的文件夹)。它以前帮助过我 -
@Codeer 不工作
-
嗯,那我就不知道了,对不起!我们很难重现您的问题。
标签: java css spring-mvc netbeans-8