How to write Servlet hello world Example

Here we will learn to create simple web application with Servlet sending Hello World to JSP page.

 Step 1 : Create Dynamic Web Application

First step would be to create a dynamic web application in Eclipse. To create this go to File >> New >> Other >> Dynamic Web Project. Provide the name of this project as “HelloWorldServlet“.

Step 2 : Create Servlet

Once application created next step would be to create Servlet which will handle the request. Create Servlet named “HelloWorld.java” in com.jbt package.
HelloWorld.java

Step 3 : Map URL to Servlet

Now you have created Servlet. Next step would be to map this servlet to an URL(/HelloWorld). You need to add an entry for this in web.xml(WebContent\WEB-INF).

web.xml

Here we will learn to create simple web application with Servlet sending Hello World to JSP page.

Step 1 : Create Dynamic Web Application

First step would be to create a dynamic web application in Eclipse. To create this go to <strong>File &gt;&gt; New &gt;&gt; Other &gt;&gt; Dynamic Web Project. </strong>Provide the name of this project as “<strong>HelloWorldServlet</strong>”.

Step 2 : Create Servlet

Once application created next step would be to create Servlet which will handle the request. Create Servlet named “<strong>HelloWorld.java</strong>” in com.jbt package.
HelloWorld.java

Step 3 : Map URL to Servlet

Now you have created Servlet. Next step would be to map this servlet to an URL(/HelloWorld). You need to add an entry for this in <strong>web.xml(WebContent\WEB-INF).</strong>

web.xml

Step 4 : Run Server and Test

Now everything is in place. So start the server and hit the URL (http://localhost:8080/HelloWorldServlet/HelloWorld).

And check the output in console. It should display “Hello World“. Till now we have not directed response to JSP so it will get displayed in Console only. In next article will display this output in JSP page.

1 Comment How to write Servlet hello world Example

Leave A Comment

Your email address will not be published. Required fields are marked *