Servlet Programming

To simplify the development of servlets, SunMicroSystems has given a predifined classes. They are "GenericServlet" and "HttpServlet". The following figure shows the relationship between classes.


relationship between servlet classes.
relationship between servlet classes.



From the above figure we can understand that Servlet is an Interface which was implemented by GenericServlet class. And HttpServlet is the sub-class of GenericServlet class. Both HttpServlet and GenericServlet classes are abstract. 

People say that there are three ways to develop the servlets. But according to SunMicroSystems, it is recommended to develop a servlet based on HttpServlet class, so that we can remove the redundant code of init(), destroy(), getServletConfig(), getServletInfo(). The following is the servlet based on HttpServlet. 

httpServlet
servlet based on HttpServlet


When we observe the above program, it doesn't have a main() method. Generally servlets doesn't consists a main() method, because servlets are executed by server not by JVM. At the same time in the above program we can see System.out.println("we are in First Servlet"). Since servlet program is executed by server the message "we are in First Servlet" will be displayed in server, which we cannot see. So, in servlet if we would like to display a message, it should be placed in PrintWriter object. The following program shows you, how to use PrintWriter object.

program shows you, how to use PrintWriter object
program shows you, how to use PrintWriter object

     
                                              

5 comments:

  1. There are lots of information about java have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get to the next level in big data. Thanks for sharing this.

    Hadoop Training Chennai
    Hadoop Training in Chennai
    Big Data Training in Chennai

    ReplyDelete
  2. This error message refers to the problem on your hard drive or issues during the process of the reading disk with the operating system. When meeting such an issue, no matter how many times you restart your computer by pressing “Ctrl+Alt+Del” keys, this error still exists. In fact, read disk error is not such a problem that can be solved by a simple restart. In this case, you are very upset and don’t know what should do. Don’t worry, this post will tell you its reasons and some useful solutions below. you must use the windows cannot be installed gpt. And the procedure is very simple for Windows and server users. Only three-step, users could recover the lost, deleted, formatted, corrupt files easy and safe.

    ReplyDelete
  3. Thank you so much for sharing this pretty post,It's a nice Article,
    seleniumtraining in hyderabad

    ReplyDelete