This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets HelloWorld

 
Douggie Fox
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've started to look at Servlets but I'm struggling getting started. Here's where I'm up to:
1. Installed Tomcat 5.0 to c:\tomcat
2. Written and compiled HelloWorld servlet
3. Started Tomcat & navigated to http://localhost:8080 and the default page comes up. The preinstalled demonstration servlets work ok.
However....

I'm following Jason Hunter's Java Servlet Programming and he says to copy the HelloWorld.class file to c:\tomcat\webapps\ROOT\WEB-INF\classes, which I've done, and then navigate to http://localhost:8080/servlet/HelloWorld. Tomcat responds with:
HTTP Status 404 - /servlet/HelloWorld...the requested resource is not available...

I'm unsure whether I've put the class file in the right place or that I'm missing something. Do I need to do something with web.xml in this basic example?
Best
DF
 
Douggie Fox
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...found my own solution
... to do with the the Invoker Servlet
reference to http://www.coreservlets.com/Apache-Tomcat-Tutorial/#Enable-Invoker

Best
DF
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you found a solution.
Just to let you know that relying on the "invoker" is generally considered a bad idea these days, which is why recent Tomcat releases have it disabled by default.
A more robust solution, which should also help you develop your understanding of servlets and web applications generally, would be to create a file "web.xml" in c:\tomcat\webapps\ROOT\WEB-INF containing ssomething like the following:

Then you should be able to turn off the invoker again, and access your "hello world" servlet using the simpler URL http://localhost:8080/hello
Apologies if you already knew all this.
 
Douggie Fox
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Frank,
Thanks for the info. I think I was 2 steps away from concluding the same thing. I had read the warnings about it being "a bad thing"...just wanted to get past chapter 1 though
Best
DF
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic