Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.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 spring mvc资源不可访问_Java_Spring_Spring Mvc - Fatal编程技术网

Java spring mvc资源不可访问

Java spring mvc资源不可访问,java,spring,spring-mvc,Java,Spring,Spring Mvc,我不明白,为什么当我试图访问由配置的静态资源时,所有建议都不起作用 我只需要包括Jquery。通过远程google url,它可以工作,但我无法从自己的资源访问它: <spring:url value="/resources/js/jquery-1.11.3.js" var="jqueryJs" /> <script src="${jqueryJs}"></script> 以下是我的项目结构: web.xml http://java.sun.com/x

我不明白,为什么当我试图访问由配置的静态资源时,所有建议都不起作用

我只需要包括Jquery。通过远程google url,它可以工作,但我无法从自己的资源访问它:

<spring:url value="/resources/js/jquery-1.11.3.js" var="jqueryJs" />
<script src="${jqueryJs}"></script>

以下是我的项目结构:

web.xml

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd“id=“WebApp\u id” version=“3.0”>


调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
/
上下文配置位置
/WEB-INF/dispatcher-servlet.xml
org.springframework.web.context.ContextLoaderListener
调度程序servlet:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Activates various annotations to be detected in bean classes -->
    <context:annotation-config />

    <!-- Scans the classpath for annotated components that will be auto-registered as Spring beans. For example @Controller 
        and @Service. Make sure to set the correct base-package -->
    <context:component-scan base-package="indoorGPS" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:annotation-driven />

</beans>

/WEB-INF/pages/
.jsp
我发现了,我补充道

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.js</url-pattern>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>

违约
*.js
*.css
对于web.xml,可以找到资源,但同样:我不明白为什么这个“默认servlet”解决了这个问题,为什么忽略了mvc:resources(我可以删除它,但它没有任何效果)

以下是我在jsp中访问资源的方式:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Activates various annotations to be detected in bean classes -->
    <context:annotation-config />

    <!-- Scans the classpath for annotated components that will be auto-registered as Spring beans. For example @Controller 
        and @Service. Make sure to set the correct base-package -->
    <context:component-scan base-package="indoorGPS" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:annotation-driven />

</beans>


我做错了什么?为什么会这样呢?

for Spring Dispatcher servlet应该在web.xml中
/*
,以便对任何资源(包括静态文件)的任何请求都会到达Dispatcher servlet。一旦控件到达,根据
mvn:resources
配置,如果静态文件URLtains
/resources/
在其中,它将通过将资源直接映射到您的
resources
文件夹来为资源提供服务。不幸的是,这会导致堆栈溢出错误,并且不起作用。这是为您做的吗?您可以将异常堆栈跟踪添加到您的问题中吗?