• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat is not finding my class

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, first post. I'm trying to get a servlet running, but it keeps 404ing on me. I checked the FAQ, and other than the use of a package (which I deliberately am not doing yet) everything looks fine. This is on Kubuntu 10.10 with Tomcat6 and Sun java.

First of all, let's make sure that everything is right:


The Page.class file compiled with no problems, and I did restart tomcat after putting everything in it's place. However, when I try the address http://127.0.0.1:8080/test/foo I get a 404 error. I know that this is the right server root directory, because I could edit /var/lib/tomcat6/webapps/ROOT/index.html in VI and see my edits on http://127.0.0.1:8080. So, what appears to be wrong?

Thanks!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dotan Cohen wrote:and other than the use of a package (which I deliberately am not doing yet)



This is like saying "And other than putting gas in the tank (which I am deliberately no doing yet)" and wondering why the car won't start.

Put the servlet, and any other classes, in a package.
 
Dotan Cohen
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All right, Bear, I thought that was unnecessary at this stage but I'm willing to learn! Thanks.

Putting the code in a package didn't help, though. Here is everything that I think one would need to know:


Did I write the web.xml file wrong? This is what I suspect.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is test under ROOT?

And foo.html as a mapping is folly. You're going to screw up the caching because everything assumes that anything ending with .html is a static resource.
 
Dotan Cohen
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Why is test under ROOT?



Because ROOT is the tomcat webroot. Was that a bad assumption on my part? Moving test/ up a directory (to be a sibling of ROOT) results in the same situation, so where should I put it?


And foo.html as a mapping is folly. You're going to screw up the caching because everything assumes that anything ending with .html is a static resource.



Yes, of course. This is just until I get "Hello, world" out the door. Though to be honest, even on production dynamic sites I do prefer the .html ending and the proper headers to prevent caching. The nice thing about that is that I can use different technologies under the hood (Python, PHP). But that is a whole other discussion, to be sure!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dotan Cohen wrote:Because ROOT is the tomcat webroot.


It is not. It is the root web application. You are trying to put one web app inside another.

For automatic deployment, web apps should have their context root (folder with WEB-INF) in the webapps folder.

Though to be honest, even on production dynamic sites I do prefer the .html ending and the proper headers to prevent caching.


Maximum folly. All you will do is to create non-deterministic behavior. If you want to prevent caching, just do so with the proper HTTP headers.

The nice thing about that is that I can use different technologies under the hood (Python, PHP). But that is a whole other discussion, to be sure!


There is no nice thing about it. It will lead to eventual disaster. I have the scars to prove it. Use mappings without any associated file type.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you keep showing the source folders? They are of no runtime interest. The context root and below are all that matter at run time.

Have you used the Tomcat manager to verify that your web app is even loading?
 
Dotan Cohen
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Dotan Cohen wrote:Because ROOT is the tomcat webroot.


It is not. It is the root web application. You are trying to put one web app inside another.

For automatic deployment, web apps should have their context root (folder with WEB-INF) in the webapps folder.



Thanks, I did not know that. Well, it is now in webapps (see previous post) but it still won't find the class. So I must have another error somewhere.

Maximum folly. All you will do is to create non-deterministic behavior. If you want to prevent caching, just do so with the proper HTTP headers.


I do just that! I don't rely on the filename to prevent caching!


There is no nice thing about it. It will lead to eventual disaster. I have the scars to prove it. Use mappings without any associated file type.


I know that you are right. So far I've been careful with .htaccess to determine which technology should parse which page. I know that is an accident waiting to happen. It's just hobby sites like my homepage, though, nothing critical. When I finish my studies I certainly _won't_ play around like that on an employer or customer's site!

I really do appreciate your patience in helping me. If there is a fine manual that I should be reading, I'd love to know the URL. I am sharing a copy of the JSP and Servlets Head First book with another student, but it's now at his place and I won't get it back until Wednesday. In the meantime, I'd really like to get tomcat parsing and serving my pages.

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the Tomcat documentation. Get the manager app running.
 
Dotan Cohen
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Read the Tomcat documentation. Get the manager app running.



Thanks, Bear. I found this fine manual:
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html

I configured a manager in /etc/tomcat6/tomcat-users.xml and logged in with HTTP credentials. I then tried these two commands to deploy the servlet:



I also tried with the http://127.0.0.1:8080/manager/html interface, but with all that I've played around with the values I get the same failure error as above. However, I seem to now be stuck with this entry that will not start and will not undeploy:
Path: /test
Display Name:
Running: false
Sessions: 0

Clicking "start" gives this error:
FAIL - Application at context path /test could not be started

And clicking "undeploy" gives this message:
OK - Undeployed application at context path /test
However, the application still appears in the list and I still cannot start it.

I'm at a loss. Where should I go from here?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Time to look in the logs. Something is keeping your app from deploying.
 
Dotan Cohen
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Time to look in the logs. Something is keeping your app from deploying.



Thanks, I found this in the catalina logs:


The line/column in question is the end of the </servlet-mapping> line. Googling I don't see exactly what I should put in the <url-pattern> tag. In fact, it looks completely optional from what I gather. I called Natalia (the girl with the Head First book) and she insists that on the example page in the first chaper there is no url-pattern tag, in fact, she insists (and I remember) that the example wasn't in a package either!

What do you think, Bear? The fine manual is a bit terse for me to understand what is necessary, and I found no tutorials for this config file. I found people having trouble with asterisks and such, but nothing relevant for my issue.

The catalina log is here if you need:
http://pastebin.com/CsZE3dbY

And here is the localhost log:
http://pastebin.com/Uk6CxHX6

Thanks.
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the contents of web.xml now?

Also, none of the later "tree" outputs shows any class files inside of WEB-INF/classes.
 
Dotan Cohen
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What are the contents of web.xml now?



I changed it to this:


Now, I'm getting a 404 error, but it is complaining about not finding the class:


Also, none of the later "tree" outputs shows any class files inside of WEB-INF/classes.



You are right! That was the problem, along with the web.xml issue (and not being in webapps earlier). I'm such a noob!



Ulf and Bear, thank you very, very much for your help and your patience. I certainly learned a lot from this issue, not the least of which is to familiarise myself with the Tomcat docs and log files. Have a terrific week!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic