Servlets

getProtocol() Method Example

getProtocol() method is defined in ServletRequest interface from javax.servlet package and inherited by HttpServletRequest. With getProtocol() method, the Servlet Programmer can know what protocol (like HTTP/1.0 or HTTP/1.1) is used by the client from HTML file to call the Servlet. Let us see what Java API says about this method. java.lang.String getProtocol(): Returns the name …

getProtocol() Method Example Read More »

getServletPath() Method Example

Programmer uses getServletPath() method to retrieve the alias name used by client. getServletPath() Method is defined in ServletRequest inherited by HttpServletRequest. This program uses getServletPath() of HttpServletRequest to retrieve the alias name (of <servlet-mapping>) tag. Client uses this alias name to call the Servlet. Following is the method signature. Method is defined in HttpServletRequest interface. …

getServletPath() Method Example Read More »

getRequestURL() vs getRequestURI()

getRequestURL() vs getRequestURI() methods are used by Servlet Programmer to retrieve the URL particulars of client. getRequestURL() and getRequestURI() methods are defined in HttpServletRequest interface. These two are used by the Servlet to retrieve the URL information (written in ACTION attribute of FORM tag) used by the client to call the servlet. getRequestURL() vs getRequestURI() …

getRequestURL() vs getRequestURI() 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 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 »

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 »

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 »

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 »