Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve static content from tomcat

Tags:

java

tomcat

People also ask

Can Tomcat serve static files?

Tomcat will serve any static content from a WAR file using the DefaultServlet.

How static files are served in Apache?

In this article we will see how we can configure Apache server for serving static content. For example, the URL http://localhost/static/logo.png will send the image ./static/logo. png to the client. The alias directive element allows documents to be stored in the local file system other than under the DocumentRoot.

How does Tomcat server work internally?

Tomcat receives a request from a client through one of its connectors. Tomcat maps this request to the appropriate Engine for processing. These Engines are contained within other elements, such as Hosts and Servers, which limit the scope of Tomcat's search for the correct Engine.


Don't put them into WEB-INF, that folder is for the stuff that you do not want to have directly served.

Put it next to WEB-INF

+- WEB-INF
+- static

The files should not be inside WEB-INF. They must be placed directly inside your web-applications directory or WAR file.

Look at my answer here for including the context path before your static resources.


WEB-INF is a protected directory. They must be placed in or in a subdirectory in the top level web app directory.