Personal Website and Computer Science TUR EN

Servlet Build Deploy Run Hello World Application

Last update: 5/3/2017 6:34:00 AM


To understand how servlet works on Apache web server, it is better to start from the beginning without using any IDE, or helper application that organizes the environment for you. Implementing the following steps is enough to make your Hello World application worked.

This article assumes that you have already had a Java environment and Apache server in your system.

1. Create a class HelloWorldServlet

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		PrintWriter out = response.getWriter();
		out.println("<html><body><h1>Hello World</h1>");
		java.util.Date now = new java.util.Date();
		out.println("<h1>Time: " + now + " </h1></body></html>");

Put this java file into src folder.

2. Create a web.xml file

<?xml version="1.0" encoding="ISO-8859-1" ?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

        This is a simple web application with a source code organization
        based on the recommendations of the Application Developer"s Guide.




Put this file into etc folder.

3. Create a directory structure as below.

4. Move the project root folder with the sub files to under the webapps folder where apache server places its web applications. Example path for windows, depends on your environment, D:\Apache Software Foundation\apache-tomcat-7.0.47\webapps\

5. Build the project under the apache web application project directory.

6. Jump to tomcat directory in cmd

D:\Apache Software Foundation\apache-tomcat-7.0.47

7. Compile the source java file

javac -classpath lib/servlet-api.jar -d webapps/ServletHelloWorld/WEB-INF/classes webapps/ServletHelloWorld/src/HelloWorldServlet.java

8. Open up the browser and run the application.


There has been no comment yet


   Please verify the image

The Topics in Computer Science

Search this site for


Software & Algorithms


In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning.

Programming Languages


A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. It can be used to create programs to control the behavior of a machine. Java,C, C++,C#



A database is an organized collection of data. The data are typically organized to model aspects of reality in a way that supports processes requiring information.



Computer hardware is the collection of physical elements that constitutes a computer system. Computer hardware refers to the physical parts or components of a computer such as the monitor, memory, cpu.

Web Technologies


Web development is a broad term for the work involved in developing a web site for the Internet or an intranet. Html,Css,JavaScript,ASP.Net,PHP are one of the most popular technologies. J2EE,Servlet, JSP,JSF, ASP

Mobile Technologies


Mobile application development is the process by which application software is developed for low-power handheld devices, such as personal digital assistants, enterprise digital assistants or mobile phones. J2ME



A computer network or data network is a telecommunications network that allows computers to exchange data. In computer networks, networked computing devices pass data to each other along data connections.

Operating Systems


An operating system is software that manages computer hardware and software resources and provides common services for computer programs. The OS is an essential component of the system software in a computer system. Linux,Windows

Computer Science


Computer science is the scientific and practical approach to computation and its applications.A computer scientist specializes in the theory of computation and the design of computational systems.