Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.
(Answer) (Category) Java Apache Project : (Category) Apache JServ 1.0 : (Category) Programming and Misc. Tidbits :
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?
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)

[Append to This Answer]
Previous: (Answer) How do I properly parse a query string that I receive from the browser? I am having trrouble...
Next: (Answer) How do I create an image with a servlet, for example, a graph out of a list of values?
This document is: http://java.apache.org/faq/?file=199
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.709.
Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.