Servlet


A servlet is a Java program that runs on a Web server. It is just like an applet, however is processed on the server reasonably than a consumer’s machine. Servlets are sometimes run when the consumer clicks a hyperlink, submits a type, or performs one other sort of motion on an internet site.

Both servlets and JSP pages comprise Java code that’s processed by a Web server. However, servlets are primarily Java packages, whereas JSP pages are primarily HTML recordsdata. In different phrases, a servlet is a Java program which will comprise HTML, whereas a JSP web page is an HTML file which will comprise Java code. Additionally, servlets require a particular construction and should comprise the next three strategies:

  1. init()
  2. service()
  3. destroy()

The init() methodology initializes the servlet, allocates reminiscence for the method, and passes any enter parameters to the servlet. The service() methodology, which can even be specified because the doGet(), doPost(), doPut(), or doDelete() methodology, processes the HTTP request and usually gives a response that’s despatched to the consumer’s browser. The destroy methodology could save information to a log file and frees up sources that had been utilized by the servlet.

Servlets are considered one of many choices Web builders can use to create dynamic web sites and course of information entered by web site guests. Since they’re written in Java, servlets present a straightforward manner for programmers who’re already acquainted with the Java programming language to create Web purposes.

Looking to know more Internet Terms