Servlet

A servlet is a Java program that runs on a Web server. It is similar to an applet, but is processed on the server rather than a client's machine. Servlets are often run when the user clicks a link, submits a form, or performs another type of action on a website.

Both servlets and JSP pages contain Java code that is processed by a Web server. However, servlets are primarily Java programs, while JSP pages are primarily HTML files. In other words, a servlet is a Java program that may contain HTML, while a JSP page is an HTML file that may contain Java code. Additionally, servlets require a specific structure and must contain the following three methods:

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

The init() method initializes the servlet, allocates memory for the process, and passes any input parameters to the servlet. The service() method, which may also be specified as the doGet(), doPost(), doPut(), or doDelete() method, processes the HTTP request and typically provides a response that is sent to the client's browser. The destroy method may save data to a log file and frees up resources that were used by the servlet.

Servlets are one of many options Web developers can use to create dynamic websites and process data entered by website visitors. Since they are written in Java, servlets provide an easy way for programmers who are already familiar with the Java programming language to create Web applications.

Updated October 20, 2012 by Per C.

quizTest Your Knowledge

What is the primary difference between the C and C++ programming languages?

A
C runs on any system, while C++ only runs on mobile devices
0%
B
C can only be compiled for one platform, while C++ is multi-platform
0%
C
C requires strict syntax, while C++ is more flexible
0%
D
C does not support object-oriented programming, while C++ does
0%
Correct! Incorrect!     View the C++ definition.
More Quizzes →

The Tech Terms Computer Dictionary

The definition of Servlet on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please use the green citation bar directly below the definition.

Our goal to explain computer terminology in a way that is easy to understand. We strive for accuracy and simplicity with every definition we publish. If you have feedback about this definition or would like to suggest a new technical term, please contact us.

TechTerms Newsletter

Improve your technical knowledge with our daily or weekly newsletter! Subscribe today and get new terms and quizzes delivered to your inbox.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.