File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to "Hello World"?" Watch "How to "Hello World"?" New topic

How to "Hello World"?

nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
I have a very simple program HelloWorld as;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
I compiled and stored it under path
Aslo I have c:\tomcat\Webapps\HelloWorld\Web-inf\web.xml as following;
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE web-app (View Source for full doctype...)>
- <web-app>
- <!-- Your servlet definitions go here
- <servlet>
- <servlet-mapping>
After start tomcat, I typed URL in browers as; http://localhost:8080/HelloWorld
what I can see is ;
Directory Listing for:/HelloWorld
Up to:/

Tomcat Web Server v3.2.1 "
But according to the book(Core Servlets & JavaSerer Page), I should see
Hello World
Anybody know what is going wrong?

Have you tried this Mock Exam Testing Engine yet?<br /><a href="" target="_blank" rel="nofollow"></a>
Jimi Rock
Ranch Hand

Joined: Feb 19, 2001
Posts: 134
Store your classes under:
Call your class as follows: http://localhost:8080/examples/servlet/yourclassname
nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
Hi Jimi,
It works!!! Thank you!
It looks like your way is simple and easy- do not need web.xml file. But I can not find any documents explain to me how your way works. I thought this way can not work for tomcat.
Hope you enjoy the URL I found!
Jimi Rock
Ranch Hand

Joined: Feb 19, 2001
Posts: 134
Nan, it works for tomcat. why not?
note that I did find this way my self , I will tell you how:
When I run an already exist servlet example, I call the html file that exist under tomcat_home/webapps/examples/servlets
then I have noticed that when I submit a request the following url is appered in my browser title bar: http://localhost:8080/examples/servlet/classfilename.
so I have edited my servlets and compile them , then save them under the classes directory. then call them as specified . that's all!
I agree. Here's the link:
subject: How to "Hello World"?
It's not a secret anymore!