• 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

Servlet invoking problem

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My system is w2k, with tomcat 4.0.3, which runs pretty well, I can check out the tomcat page via http://localhost/ (I have changed the port number from 8080 to 80). And the example servlets and JSPs also work very well.
Following the tutorial at http://www.moreservlets.com/Using-Tomcat-4.html,
Quote from the tutorial:
"Once you compile HelloServlet.java, put HelloServlet.class in install_dir/webapps/ROOT/WEB-INF/classes. After compiling the code, access the servlet with the URL http://localhost/servlet/HelloServlet (or http://localhost:8080/servlet/HelloServlet if you chose not to change the port number as described earlier)."
I compiled a HelloWorld.java servlet code and copied the HelloWorld.class file into install_dir/webapps/ROOT/WEB-INF/classes, that is, the full path to HelloWorld.class is install_dir/webapps/ROOT/WEB-INF/classes/HelloWorld.class. Then I accessed the servlet via the url http://localhost/servlet/HelloWorld and got tons of exception in the browser.
What might be the problem? Thanks a lot.
Gene
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there.
You might want to post the exceptions (or at least the first couple of lines) but i suspect that you have deployed the servlet in the wrong directory. Alternatively take a look at the presentation that I presented at JavaOne last year on deploying web applications. The presentation can be found on my website at http://www.samjdalton.com under the conferences link
Rgds
sam
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gene,
I justed installed Tomcat 4.0.3 on my system the last two days and followed the tutorial from Marty Hall's site that you mentioned. The problem is this:
I believe he wrote the tutorial for Tomcat 4.0.0 or something like that. I even had to put the classes and lib subdirectories in the WEB-INF directory under install_dir/webapps/ROOT and the HelloWorld servlet still did not work. If you notice the example servlets are run from a subdirectory /examples. The difference however lies in the fact that that under the examples directory the WEB-INF directory has the proper web.xml descriptor with the necessary sevlet-mapping and servlet-invoking characteristics.
Try copying the .class file to install_dir/webapps/ROOT/examples/WEB-INF/classes and then accessing it via http://localhost/examples/servlet/HelloWorld. I think you will see that everything is fine after this.
[ March 12, 2002: Message edited by: Eric Peterson ]
 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric:
Actually, the tomcat example classes are put into
install_dir/webapps/examples/WEB-INF/classes, I think you had a typo in your post. I know the servlet classes work nicely if we put we them there. But that's what I don't like. So we really need a web.xml file under the our own web application directory?
[ March 12, 2002: Message edited by: Gene Chao ]
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well yes, that's right.

Each directory is a web-app. Each web-app should have its own web.xml This is not unreasonable, and is part of the standard, anyways.

The tutorial linked is really a *BAD* way of doing things (using the /servlet default mapping). This promotes lazy development methods, and it is not supported (or the support is different) in different containers.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic