Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

basic question: display a sample helloworld servlet  RSS feed

 
biagio renda
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
 
William Brogden
Author and all-around good cowpoke
Rancher
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
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!