• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

basic question: display a sample helloworld servlet  RSS feed

 
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: 42974
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.
 
Sheriff
Posts: 67257
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
You can't expect to wield supreme executive power just because
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!