Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用SpringMVC时无法加载css和js文件_Java_Spring Mvc - Fatal编程技术网

Java 使用SpringMVC时无法加载css和js文件

Java 使用SpringMVC时无法加载css和js文件,java,spring-mvc,Java,Spring Mvc,我是Spring MVC的新手。对于加载资源,我使用了。虽然这很有效,但现在不是。我不能理解这个问题。有人能帮我吗 这是我的spring-dispatcher-servlet.xml。 我的资源(设计)文件夹位于WebContent中,它有称为css、js和图像的子文件夹 < beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/sche

我是Spring MVC的新手。对于加载资源,我使用了
。虽然这很有效,但现在不是。我不能理解这个问题。有人能帮我吗

这是我的spring-dispatcher-servlet.xml。 我的资源(设计)文件夹位于WebContent中,它有称为css、js和图像的子文件夹

< 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"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<context:component-scan base-package="controller"/> 

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean> 

<bean id="viewResolverhtml" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/</value>
    </property>
    <property name="suffix">
        <value>.html</value>
    </property>
</bean> 

<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
    <property name="host" value="localhost"/>
</bean>

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongo" ref="mongo"/>
    <constructor-arg name="dabaseName" ref="testdb"/>
</bean>

<mongo:repositories base-package="model"/>

<mvc:view-controller path="/" view-name="index"/>
<mvc:resources mapping="/design/**" location="/design/" />

<mvc:annotation-driven/>

/
.jsp
/
.html

这就是我在index.jsp中加载资源的方式

<link rel="stylesheet" href="design/css/reset.css" type="text/css" media="screen">
<link rel="stylesheet" href="design/css/style.css" type="text/css" media="screen">
<link rel="stylesheet" href="design/css/grid.css" type="text/css" media="screen">
<script src="design/js/jquery-1.6.3.min.js" type="text/javascript"></script>
<script src="design/js/cufon-yui.js" type="text/javascript"></script>
<script src="design/js/cufon-replace.js" type="text/javascript"></script>
<script src="design/js/Kozuka_Gothic_Pro_OpenType_300.font.js" type="text/javascript"></script>
<script src="design/js/Kozuka_Gothic_Pro_OpenType_500.font.js"  type="text/javascript"></script>
<script src="design/js/FF-cash.js" type="text/javascript"></script>
<script type="text/javascript" src="design/js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="design/js/tms-0.3.js"></script>
<script type="text/javascript" src="design/js/tms_presets.js"></script>
<script src="design/js/jcarousellite_1.0.1.js" type="text/javascript"></script>

尝试以下任一方法:

带JSTL标记c:url

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link href="<c:url value="/design/css/reset.css" />" rel="stylesheet">
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:url value="/design/css/reset.css" var="reset" />

带spring:url

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link href="<c:url value="/design/css/reset.css" />" rel="stylesheet">
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:url value="/design/css/reset.css" var="reset" />

没有任何标签

<link href="${pageContext.request.contextPath}/design/css/reset.css" rel="stylesheet"

谢谢您的回答