aspose file tools*
The moose likes Servlets and the fly likes Servlets HelloWorld Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets HelloWorld" Watch "Servlets HelloWorld" New topic
Author

Servlets HelloWorld

Douggie Fox
Greenhorn

Joined: Jun 14, 2001
Posts: 19
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

Joined: Jun 14, 2001
Posts: 19
...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

Joined: Jan 07, 1999
Posts: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Douggie Fox
Greenhorn

Joined: Jun 14, 2001
Posts: 19
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets HelloWorld