问题
For starters, we are running Tomcat8, Java8, and Windows Server 2012.
We store images, styles, JavaScript, and other static resources in directories outside of our web application called "shared" and "uploads". To configure this, I create a base context that all apps that looks like this:
<Context>
<Resources>
<PreResources base="${document.root}\shared" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/shared" />
<PreResources base="${document.root}\uploads" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/uploads" />
</Resources>
</Context>
And in addition, there is a site specific context that would look like this:
<Context docBase="${document.root}\sitename">
</Context>
We were noticing that some requests to the shared directory were working and others were not. I figured out that it has to do with the file name casing. Some files within shared have names that start with lower case letters and some with upper case. Those that have lower case names work fine. So to test a theory, I made two requests to the same file name (one that does not exist), changing only the casing, so I could see the 404 page and see the file path actually being used.
I first requested this URL:
{domain}/shared/Base.js
The resulting 404 page indicates that Tomcat searched for this path:
/shared/base.js
I then requested this URL:
{domain}/shared/base.js
The resulting 404 page indicates that Tomcat searched for this path:
/shared/base.js
As you can see, no matter what casing I use in the URL, it seems to convert it to lower case. So if I go and rename one of the files that is failing to an all lower case name, everything works. The problem is these are large directories and we are aiming to upgrade our server without a coinciding code update. Also, the content in uploads is submitted by our users and outside of ensuring unique names, we do not alter the file names so casing will continue to be random. Is anyone aware of some attribute or configuration I can use to get Tomcat to use the file name exactly as it is provided in the URL?
来源:https://stackoverflow.com/questions/31862248/case-sensitivity-issue-with-tomcat-8-resources-preresources