You have to map your servlet to a URL either by a WebServlet annotation in the Java file, or a servlet mapping in web.xml. Are you doing either one of those? Are you doing both? I don't recommend doing both at the same time because it can make it confusing what the actual mapping will be. Another common problem is relying on the annotation technique, but then setting a flag in the web.xml: metadata-complete="true", which tells Tomcat to ignore the annotations.
Joined: Mar 21, 2001
I'll look into that, try a few things out and then get back to you.
At the moment, with all my annotation and web.xml "magic",
I need to place my jsp in $CATALINA_HOME/webapps/reverse2/
and my servlet class in $CATALINA_HOME/webapps/reverse2/WEB-INF/classes/com/javaranch/drive.
Am I supposed to have my reverse servlet in ROOT at all?
I guess so, though. Just need a bit of feedback on that, there was a thread in this saloon
which mentioned the non-ROOT approach, unless I misread.
No, there shouldn't be any need to put anything into webapps/ROOT. ROOT is really just another web application, but it's one we don't have to alter to make the servlet assignments work. Putting your servlet class into $CATALINA_HOME/webapps/reverse2/WEB-INF/classes/com/javaranch/drive is perfect. That's exactly where you want it. You can't type the Java class name into your browser URL though, so that's what the mapping (aka "magic") is for.
Joined: Mar 21, 2001
Hi Greg, I think I'm getting it slowly. The latest Assignment description you sent me had more information on the web.xml. Until then, I'd been running on old data from back in the old "orion" days. I now have a web.xml in my $CATALINA_HOME/webapps/reverse2 dir and have removed the metadata-complete attribute. Seems to be working now. Looking forward to your nitpicking, but don't let me press you
I looked at your linked thread, and see that you removed the metadata-complete attribute in your final working web.xml.
I'd say, that was it. I tried it with and without, restarting tomcat each time, to be sure. And it only sparked correctly when I removed the entry from my web.xml.
Well, it's certainly possible. There are still some points about "metadata-complete" that are unclear to me. Some resources say that setting it to true will only prevent annotations in the WEB-INF/lib jar files from being considered, while others say that even annotations in application classes in WEB-INF/classes will be ignored. Even the official Servlet spec doesn't make this point exactly crystal clear. From testing the the servlet assignments in Tomcat, I've found that the annotations still work with metadata-complete set to true until the assignments where the servlet is an extension of ActionServlet. Maybe because ActionServlet exists in a lib Jar file? It doesn't really make sense, since that's not where the annotation is.
Someday, I'll look more closely at that, but for now, it's best to leave that flag off, or set it to false. Its purpose is to speed up loading of web applications that include very large Jars in their WEB-INF/lib folder, and we're not doing anything that big in the assignments.