Series: Servlets introduction

Servlets introduction for beginners with explanation, examples and screenshots

Servlets Tutorial Architecture Introduction

For easy understanding, the Servlets Tutorial Architecture is given in Question/Answer format. 1. What is Component? A Component is a reusable software unit. 2. What is server-side component? In client/server communication, a server-side component is that one which is automatically invoked against client request, executed and responses to client fulfilling the requirement. 3. What is …

Servlets Tutorial Architecture Introduction Read More »

Servlets Tomcat Execution in 7 Steps

Servlets Tomcat: Install Tomcat server of your choice version by downloading from Apache site. Many versions of Tomcat can be found in the following link. http://tomcat.apache.org/download-60.cgi Check with the documentation of what JDK or JRE version is compatible to the specific Tomcat version. For example I loaded Tomcat 5.0 and is compatible with JDK 6.0. …

Servlets Tomcat Execution in 7 Steps Read More »

Stateless and Connectionless HTTP Protocol

About HTTP Protocol What is HTTP (HyperText Transfer Protocol) Protocol? A protocol sets standards for communication between systems, client to server or among servers. HTTP is specially meant to communicate between Client and Server using Web (or Internet). It was developed by W3C (World Wide Web Consortium) around in the year 1995. HTTP is an …

Stateless and Connectionless HTTP Protocol Read More »

First Servlet Example Login Screen Validation

After going through the introduction and architecture of servlets, let us write a simple Login Validation program. As you have seen in the architecture, there will be two programs – one running on client machine and the other on server. Servlet Example explained in 10 steps First let us write the client-side program. I. Client …

First Servlet Example Login Screen Validation Read More »

Read Client HTML Form data with getParameterNames()

In the first simple program Login Screen Validation, the data sent by the client is extracted from HttpServletRequest object req, using getParameter(String) method. The getParameter(String) method works to read a single text box (or any FORM field) only. The HttpServletRequest interface comes with another method getParameterNames() (inherited from ServletRequest interface) to read all the FORM …

Read Client HTML Form data with getParameterNames() Read More »

ServletConfig Example init-param read getInitParameter()

A Servlet may have some values needed for it’s execution or a Programmer may require some values to be fed to Servlet needed in the coding for execution. These values are specific to a particular Servlet and not required for all Servlets. For this, the deployment descriptor web.xml, comes with <init-param> tag and an example …

ServletConfig Example init-param read getInitParameter() Read More »

Read HTML Form Data in 3 Styles with Servlets

One of the activities of a Servlet Developer is to read HTML form data sent by the client by clicking over Submit button. The data sent by the client lands finally in ServletRequest/HttpServletRequest object passed as parameter to service() method. To retrieve the data from ServletRequest object, the ServletRequest interface comes with three methods mostly …

Read HTML Form Data in 3 Styles with Servlets Read More »

Servlet Read text file and Return contents Example

Sometimes, the client may ask the Servlet to send the file contents of a file existing on the server. It is not file download. Here, the Servlet reads manually line-by-line and send each line separately to client. Read Servlet Read text file. Example on Servlet Read text file Client HTML Program: TextFileReadAndSend.html Getting File contents …

Servlet Read text file and Return contents Example Read More »

ServletContext Example context-param

Before going ServletContext Example, see the difference between <init-param> and <context-param>, both written in web.xml file. What is <init-param>? portnumber 8888 We have seen the above code in Servlet web xml init param Example using ServletConfig where the "portnumber" and "8888" are accessible for the particular servlet "ReadInitParamValues". Other servlets in the container cannot access …

ServletContext Example context-param Read More »

What is RequestDispatcher in Servlets?

Communication is very needed between Servlets and Container. Towards this goal Servlet API comes with three interfaces. Following table gives the list and their functionality. Interface Functionality Example with explanation and screenshots available at ServletConfig Used to communicate with Container to read web.xml (meant for one servlet only) init-param Example using ServletConfig ServletContext Used to …

What is RequestDispatcher in Servlets? Read More »