In the last post we discussed about the Servlet basics and covered the different phases of its life cycle. Over here we would try to write a very simple ‘Hello World’ servlet class. This example would be an http servlet as they are the one widely and mostly used (not the Generic one).
Servlet Code Example
To make a simple java class a servlet, we need to first extend the HttpServlet class and then write any of the doGet() or doPost() methods. In the code example below we are just going to do the same and then add some lines to say hello to this world through a web servlet.
This needs to be executed on a web server like Tomcat or even any application server like WebLogic or Websphere can do. Here goes the simplest ever code:
Hello World Servlet
The output from this program would be:
My First Hello World Servlet
Try it your own and let us know if you find it same or something different.
Happy Coding !!!