spring mvc资源无法访问

时间:2015-12-12 18:23:56

标签: java spring spring-mvc

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

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

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

这是我的项目结构:

enter image description here

的web.xml

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" ID =&#34; WebApp_ID&#34;     版本=&#34; 3.0&#34;&GT;

<display-name></display-name>



<!-- Spring MVC -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/dispatcher-servlet.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>

调度员的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>

我发现了,我添加了

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

到web.xml,找到了资源,但又一次:我不明白为什么这个&#34; default-servlet&#34;解决了这个问题以及为什么mvc:resources被忽略了(我可以删除它,它根本没有效果)。

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

enter image description here

我做错了什么?为什么它会像那样?

0 个答案:

没有答案