I'm having a servlet problem with Tomcat. My webapp looks like this:
I can access my index.jsp through http://localhost/ but when I try to go to http://localhost/Test it gives me a 404 error saying page can not be found on this server. index.jsp is located in webapps folder in that folder is a WEB-INF (in capitals) where web.xml and the code above is located. in that folder is a classes folder with Test.class in it Any ideas?
It is very likely that you are having the problem because the class is not in a package. If any class used in a servlet or JSP is not in a package, the JVM looks in the "current" directory - since you have no control over the current directory this always fails. Therefore - ALL classes used in servlet or JSP must be in a package and the location of the compiled class file must match the package. It used to be possible to get away with this when the "invoker" servlet was on by default because the invoker could locate the class. See this page in the ranch FAQ for more. Bill
If you just have an index.jsp and WEB-INF folder under webapps directly, then this would not work at all.
Joined: Dec 02, 2004
Thanks for replying so quickly! I've already tried putting it in a package but I had it working in windows before without it.
| |-Test.class with package terric;
and changed the web.xml url pattern turned into /terric.Test and also tried it as /terri/terric.Test and changed the servlet name into terric.Test
and I'd try accessing it through http://localhost/terri/terric.Test And well I knew very well this wouldn't work anyway. None of the servlets are working not even under /servlet-examples. I also tried the invoker and nothing, of course. But, jsp pages are working fine. I guess it would have to do with my httpd.conf file? I have tomcat hooked up to apache but everythings fine aside from the .class files and I've tried to manipulate the web.xml file in every imaginable way.
Joined: Dec 02, 2004
woops that file structure didnt come out right lets try again:
Author and all-around good cowpoke
Joined: Mar 22, 2000
I agree with what William says, but I'd point out that the servlet *itself* does not need to be in a package (in my experience).
How in the world do you do that without having the invoker running or writing your own classloader? Bill