[英]Netbeans Spring cannot find resource file
I found problem with connecting CSS and JS file from resource directory. 我发现从资源目录连接CSS和JS文件存在问题。
Directory structure : 目录结构:
JSP File: JSP文件:
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<spring:url value="/resources/css/style.css" var="mainCss" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Project Name</title>
<link href="${mainCss}" rel="stylesheet" />
</head>
<body>
</body>
</html>
applicationContext.xml file: applicationContext.xml文件:
<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.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-4.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.controller"/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
</beans>
When I check what is under stylesheet file in console, I found: 当我检查控制台中样式表文件下的内容时,我发现:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8080/ProjectName/resources/css/style.css".
Path is redirecting to application index. 路径正在重定向到应用程序索引。
Have you got any idea how to fix it? 你知道如何解决吗? What caused the problem?
是什么引起了问题?
Can you try to change 你能尝试改变吗
<spring:url value="/resources/css/style.css" var="mainCss" />
with 同
<spring:url value="./resources/css/style.css" var="mainCss" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.