简体   繁体   中英

Tomcat Serve Static Files

Is it possible to serve static files from Tomcat? Would Tomcat do this efficiently? From memory, I believe the Java EE spec included a clause disallowing serving static files.

Eventually I'll need to integrate a CDN as well. Would using Tomcat prevent this?

Is it possible to serve static files from Tomcat in a Spring Boot application?

Yes, of course. Opening the reference documentation and looking for "static" immediately leads to http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-mvc-static-content , which explains how to do it.

Would Tomcat do this efficiently?

Yes. Probably a bit less efficiently than nginx or Apache would do it, but it shouldn't matter much. And if it matters, then you probably want a CDN.

From memory, I believe the Java EE spec included a clause disallowing serving static files.

No. Any file inside a war file, not under WEB-INF, is served as a static resource.

Eventually I'll need to integrate a CDN as well. Would using Tomcat prevent this?

Why would it. Using a CDN simply consists in using absolute paths to some resource on the web rather than using a path pointing to your web app. Tomcat doesn't care.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM