aspose file tools*
The moose likes Cattle Drive and the fly likes Servlets-2 and 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Servlets-2 and 3" Watch "Servlets-2 and 3" New topic
Author

Servlets-2 and 3

Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
I really can't get my servlet classes to be known to tomcat when I put them in ROOT/WEB-INF.

What am I doing wrong? Or which config have I not touched correctly yet? Or which one have I broken?

All of my servlet classes are in $CATALINA_HOME/webapps/$my_servlet_name/WEB-INF/classes/com/javaranch/drive/
The jsp is in the $my_servlet_name dir.

This is crazy. Can someone help me out with a few clever questions or compare my set up to theirs?

Stuart
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

What exact exception are you seeing? Can you post that stacktrace?

$CATALINA_HOME/webapps/$my_servlet_name/WEB-INF/classes/com/javaranch/drive/


You mean my_servlet_name is the name of your web application right? ROOT in this case?


[My Blog] [JavaRanch Journal]
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

Hi Stuart,

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.
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
Greg,

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.

Stuart
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

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.
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
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
margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 318
    
    6

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.


I didn't know this and have the metadata-complete on in many of my web.xml.

Greg, could that have been what caused the problem I posted in this thread ?

web.xml problem with servlet annotations
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
Hi Margaret,

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.

I'm using annotations of course
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

margaret gillon wrote:
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.


I didn't know this and have the metadata-complete on in many of my web.xml.

Greg, could that have been what caused the problem I posted in this thread ?

web.xml problem with servlet annotations


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets-2 and 3