Pages Navigation Menu

Coding is much easier than you think

Servlet + Jsp Hello World Example

In our previous tutorial we got introduced to what a JSP is, In this article we are going to cover how to write Hello world example using both Servlet and Jsp.

Final Project Structure

Hello world using Servlet and  jsp



package com.servlet;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		RequestDispatcher rd = request.getRequestDispatcher("hello.jsp");
		rd.forward(request, response);



Make sure that your web.xml file has following mapping



JSP Page


Hello world in Servlet + JSP


Hurray!! This Servlet worked!!!



Deploy the application tomcat server and enter the URL to access HelloWorldServlet “http://localhost:8089/HelloWorldServlet/helloworld”
Run hello world servlet  JSP

One Comment

  1. Great! Keep up the good work!

Leave a Comment

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