Sometimes you need a URL to download a file, such as an Excel spreadsheet. The front end is implemented using window.open(XXX). If the URL specified directly http://xxx:8080/xxx/xxx.xlsx, throws a 404 error.

Since Tomcat only allows you to download HTML, JS, CSS, etc., we had to set up a file server.

This can be done through Tomcat’s virtual directory.

Create a new configuration file, assuming we need to access the /files path through the URL that maps to /home/tomcat/share/files, then we can configure it like this:

<? xml version="1.0" encoding="UTF-8"? > <Context antiJARLocking="true" docBase="/home/tomcat/share/files" path="/files"/>
Copy the code

After the configuration is complete, put it in the /conf/Catalina/localhost directory.

Restart the Tomcat server. Isn’t it easy