• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

basic question: display a sample helloworld servlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
  • 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: 43016
76
  • Mark post as helpful
  • send pies
  • 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.
 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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.
 
Do Re Mi Fa So La Tiny Ad
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic