开发者

Using Spring ResourceServlet to serve multiple resources simultaneously

The JavaDoc for the ResourceServlet states that it can return a list of resources. But examples of this usage pattern seem to be sparse at best.

We have a web.xml with the following:

<servlet>
  <servlet-name&g开发者_C百科t;Resource</servlet-name>
  <servlet-class>org.springframework.web.servlet.ResourceServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>Resource</servlet-name>
  <url-pattern>/combo</url-pattern>
</servlet-mapping>

When we make a request to url along the lines of: http://localhost:8080/app/combo?resource=js/file1.js;js/file2.js

We only seem to get file1 in the response.

What would a proper configuration be for this use case?


The ResourceServlet has been deprecated in favour of using <mvc:resources /> However, it doesn't handle multiple resources. You'd have to make your own controller to do that.

As for the ResourceServlet, the delimiters used in the code are ,; \t\n - any of them should work.


The problem in our case turned out to be that the application used the mvc:resource utility to handle versioning of the static files. The backend of the mvc:resource utility will not respond to multiple files properly as Bosho noted, and I was aware of too from looking at the source.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜