Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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
MVC Spring调度程序和资源文件_Spring_Spring Mvc_Dispatcher - Fatal编程技术网

MVC Spring调度程序和资源文件

MVC Spring调度程序和资源文件,spring,spring-mvc,dispatcher,Spring,Spring Mvc,Dispatcher,我与MVC Spring的调度程序有问题。我的项目结构是这样的 myproject |-- webapp |-- themes |-- theme1 |-- assets |-- css |-- js

我与MVC Spring的调度程序有问题。我的项目结构是这样的

myproject
    |-- webapp
           |-- themes
                  |-- theme1
                         |-- assets
                               |-- css
                               |-- js
                               |-- img
                               ...
                         |-- views
                  |-- theme2
                         |-- assets
                               |-- css
                               |-- js
                               |-- img
                               ...
                         |-- views
           |-- WEB-INF
我的
web.xml
文件是:

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

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

<!-- Mapping -->
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/themes/*</url-pattern>
</servlet-mapping>
但不是

/myproject/themes/theme2/assets/plugins/jquery/jquery-1.10.2.min.js
/myproject/themes/theme2/assets/css/*.* // cant access any css files

通常,您应该只配置作为调度器的1个Servlet。尝试使用标记:

<mvc:resources mapping="/assets/**" location="/path/to/your/assets/" />

你需要提供更多的细节。我不是妖怪,所以我不能盲目地分辨出什么是错的。您在哪里添加了配置?我在
dispatcherservlet.xml
中添加了配置。但问题是主题名。它是动态的。我无法修复资源路径我更新了答案以显示如何使用该路径。让我知道它是否有效。它适用于
js
文件夹中的图像文件和js文件,而不适用于
plugins
folder。让我们删除
default
的servlet映射,并将
添加到
DispatcherServlet
配置中。
<mvc:resources mapping="/assets/**" location="/path/to/your/assets/" />
<mvc:resources mapping="/assets/**" location="/myproject/themes/" />
/assets/theme2/assets/js/main.js
/assets/theme2/assets/plugins/jquery/jquery-1.10.2.min.js