Tomcat does " unescape " the underscore (_) char when it is part of a war file. Why? Is there any way to disable this?

Tim Bao

I have a web application that it is structured this way:

%TOMCAT_HOME%

    webapps
      sample_test.war

When tomcat 3.3a started, it deploy this package automatically, and make the directory like this:

%TOMCAT_HOME%
    webapps
      sample_test.war
      sample_test

Notice the last item is the directory that tomcat generates. And the directory name is ok, it does have an underline.

But when I want access an file called 'index.jsp", I cannot type http://localhost/sample_test/index.jsp. In face, to access this file, http://localhost/sample/test/index.jsp must be used.

The reason is because Tomcat do use the underscore (_) char instead of the slash (/) char.
If you download the source package of Tomcat, check out the AutoDeploy.java (or some similar name). There is a function called unEscapePath() that changes all underscores into slashes.

So, it seems that the only way to disable this is to change the source code and then recompile Tomcat, with all the "portability" issues connected, otherwise, the other solution, is to remove the underscore (_) from the name of the war file.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact