我对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>
我为* .css,* .js文件添加了默认映射,但我无法访问它们。请帮帮我。
添加信息 我可以访问这些文件
/myproject/themes/theme2/assets/js/theme.js
/myproject/themes/theme2/assets/js/common.js
/myproject/themes/theme2/assets/js/main.js
但不是
/myproject/themes/theme2/assets/plugins/jquery/jquery-1.10.2.min.js
/myproject/themes/theme2/assets/css/*.* // cant access any css files
答案 0 :(得分:0)
通常,您应该只配置作为调度程序的1 Servlet。尝试使用标签:
<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