IDependOn-Set: 1
IDependOn-Set: 119
IDependOn-Set: 197
IDependOn-Set: 199
IDependOn-Set: 2
IDependOn-Set: 204
LastModifiedSecs: 928905320
Parent: 119
SequenceNumber: 2
Title: I have a directory within my servlets directory and things break when I try to use http://www.server.com/servlets/test/TestServlet, but when I put TestServlet directly in the servlets directory and remove the "test" from the URL, things work just fine. Is this a bug? 
Part: 0
Author-Set: jon@working-dogs.com
HideAttributions: 1
LastModifiedSecs: 928905320
Type: 
Lines: 7
No, this is not a bug but a wanted feature. This problem derives from the way Java structures classes into subdirectories per package name. People suffer similar problems writing non-servlet code. (we have a love-hate relationship with this approach: it's clean, but it creates deep directory trees.) Java would expect a file called $DIR/test/SimpleServlet to have the fully-qualified classname test.SimpleServlet. It looks in the 'test' subdirectory of each directory in the classpath for files in the 'test' package.


The module currently converts a request for test/SimpleServlet into a request for the class test.SimpleServlet. It finds the class file, but gets confused because the file actually contains a definition of the file 'SimpleServlet'. In short: make sure the package name declared in the class matches the directory structure where the class file is located.


To fix this particular problem: declare the servlet using a proper package name: org.dummy.test.SimpleServlet, compile it into $ROOT/servlets/org/dummy/test/SimpleServlet.class, and make your ServletPath $ROOT/servlets. Add an alias or servlet.simple.code property to generate a shorter URL if you like. (Thanks to Martin Pool)
EndPart: 0
