Saturday, August 2, 2008

File name case sensitivity in Tomcat

Even on windows OS, you may face a problem of file name case sensitive with Tomcat 5.x. You can easily disable this behavior of Tomcat, but at the cost of code security risk.

Last fortnight, I was surprised by a typical error in my java application. The application was working file since many years. I used to run it on Adobe JRun 4 with updater 7 on my Quad Core CPU based server. As no more future development are expected on JRun and this product is going to be phased out from market in near future, I decided to switch to Tomcat
I have some development and deployment experience with Tomcat 3.x and 4.X versions. I thought, it would be cakewalk for me to deploy the existing JRun 4 based application. In less than 10 minutes I deployed the application to Tomcat and I stared testing of it for performance.
Suddenly I got an error when I clicked on one of the link in application. The link was pointing to JPG image file in folder. I thought for a moment that I forgot to copy the images folder. So I checked the location of folder and the file name too. To my surprise, both folder and file were there. I right clicked on folder to see its access permission. The permission was set to Full. I stumped. I cleared the browser cache, restarted the Tomcat, clean the temp folder etc but in vein.
For time being I decided to kept asides this problem & further continued my testing task. I got the same problem many times and this time it was not a surprise to me. On further testing I stared noticing that some of the similar kind of linking to image are working too. Not all links to images are giving an error. Is tomcat crazy, I murmured?
Now I decided to focus on this problem. I stared reading the URI to image files carefully and noticed discrepancy. The filename of image files have different file name cases. While some image naming was all in small letters, in some cases it was either all Capital letters or mix of both. I changed the file name to all small letters and checked the errant link again. This time I was able to see the image, which Tomcat refused to display earlier.
So I got a plain vanilla solution to my problem but this incident left some unanswered questions.
1. Is Tomcat case sensitive to file naming?
2. MS windows are known to be not case sensitive like Unix/Linux. Then why this behavior on windows platform.

Now I forced to look into the documentation of Tomcat. I must admit; this peculiar behavior is well documented. One has to remove the case sensitivity exclusively by considering code security threat in mind , by making changes in “context.xml” file. So here is a remedy for this behavior which may turned out to be a problem.
How to remove file name case sensitivity in Tomcat 5.x?
1.Stop the Tomcat first
2.Switch to your $CATALINA_HOME folder means a folder where Tomcat is installed.
3.Switch to conf folder.
4.Open file named as “context .xml“ in notepad.
(In Tomcat version I found this file as empty, means no tags defined.)
5. Add following line in this file.
AllowLinking = true
The putting of this line will disable case sensitivity checks for file naming. You can use any file name case pattern in your application.
I made the above mentioned changes and restarted the Tomcat. The problem got solved for good.
There is another solution. Besides this tag, you can also use this tag in Conext.xml file.
CaseSensitive = true
Important note:
As tomcat documentation suggests, the setting of value of AllowLinking or caseSensitive to “true” on MS windows platform, may pose problems like “allowing JSP source code disclosure, among other security problems”. Hence be careful.
I have decided to change the entire file naming conventions in my application to lowercase. Though it is tedious as well time taking job, but for the sake of security, I know, I have to do it.

Have you experience the similar Problem? Write your comments…


Ajay said...

I am contacting you on behalf of our technology client. Our client plans to engage with technology blogging community to share information related to latest developments in digital storage.
For this purpose we request you to send your contact information (Business address, Contact no. and E-mail id)

Waiting for your reply,
Ajay Singh
MelCole Public Relations
New Delhi - 110024 INDIA

Anonymous said...


I am Richa from SiliconIndia. I am also an avid blogger for a while now and participating actively in Indian blogosphere. I read your blog posting and found them very interesting and informative. We would love to see a copy of your blogs posted here, whenever you are posting it on Here are some of the benefits of posting your blogs here:

We have a strong community of 500,000 Indian professionals
Best blogs of 2008 to be published in a book "SiliconIndia bLoG PrinT"
Best blog to be printed in SliconIndia & SmartTechie magazines each month
Chance to be featured on homepage everyday

We appreciate your community initiative here and in helping build a more powerful India! Also, if you have any ideas or want to volunteer to help for SiliconIndia, we would be more than excited to get your help. Pls mail me back at with your suggestions and feedback.

Blog Editor – SiliconIndia