• 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

basic question: display a sample helloworld servlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello, a greeting to the people of the forum

how to display a sample helloworld servlet?

I describe all the steps that I did, some of them are improvised because did not know exactly what to do

files structure of the webapp jhtp6

C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT\


servlet source code

<WEBROOTDIR>\jhtp6\WEB-INF\classes\WelcomeServlet.java



compile servlet
>javac -classpath .;"C:\P
rogram Files (x86)\Apache Software Foundation\Tomcat 8.0\lib\servlet-api.jar" WelcomeServlet.java

compiling generate bytecode

<WEBROOTDIR>\jhtp6\WEB-INF\classes\WelcomeServlet.class


<WEBROOTDIR>\jhtp6\WEB-INF\web.xml


try to open browser and display the servlet

http://localhost:8080/jhtp6/welcome1
HTTP Status 404 - /jhtp6/welcome1

my attempt to display the servlet failed



yet webserver works with html pages

http://localhost:8080/jhtp6/web/hello.html
hello world!

system win7x64 , apache tomcat 8
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

classes/
WelcomeServlet.class



If that is indeed your directory setup then your problem is that your servlet is not in a package and thus the class can not be found by the JVM.

This is one of the most common beginner errors. Search this forum for 404 errors to see examples.

ALL classes used in servlets must be in a package because without a package the JVM looks in the "current" directory, something you have no control over.

Bill
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds as if your WEB-INF directory is at C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT\jhtp6\WEB-INF - that won't work.

It either needs to be at C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT\WEB-INF or at C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\jhtp6\WEB-INF. I recommend to use the latter, and to leave the ROOT webapp alone.
 
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
If after addressing the above you are still having issues, check the ServletsFaq for a list of checkpoints to work through. Don't be discouraged -- once you get things going, it's all much easier.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic