• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Servlets-2 and 3

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 339
7
Tomcat Server Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic