Servlets

What is 404 Not Found Error in Servlets? How to Fix it?

What is 404 Not Found Errror? It is status code of the execution of a Servlet or Web application. More clear in the next explanation. User clicks over a hyperlink, some Servlet is called, executed and the response is sent to the user. Sometimes, the mouse click on the hyperlink calls such an attribute of …

What is 404 Not Found Error in Servlets? How to Fix it? 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 »

Java Clear Concepts: 10 Servlets Advantages over ASP

I. Servlets Advantages over ASP are tabulated. Feature Servlet ASP Platform-independent Servelts are platform-independent being written in Java. Works on Windows, a Microsoft product, only. Java Benefits Servlets are written in Java and can take advantage of OOPs, robustness and most important garbage collection in code development. Written in VBScript (or JScript), a Microsoft product, …

Java Clear Concepts: 10 Servlets Advantages over ASP Read More »

Web Status codes List of Common Problems

Before going through, it is advised to read What is Status code in HTTP Servlets? and Classification of Web Status Codes in HTTP. Following table gives you the list of Web status codes. Only commonly occurring are given. Status code Value Description 100 Continue 101 Switching Protocols 102 Processing 200 OK 201 Created 202 Accepted …

Web Status codes List of Common Problems Read More »

ServletConfig vs ServletContext

After knowing fully of ServletConfig and ServletContext with examples, explanation and screen outputs, it is time to compare them for still better understanding. ServletConfig vs ServletContext: Following table summarizes the differences between the two. S.No. ServletConfig ServletContext 1 Defined in javax.servlet package. Defined in the same javax.servlet package. 2 Values are placed in web.xml file. …

ServletConfig vs ServletContext Read More »

What is ServletContext interface?

ServletConfig interface is specific to a particular Servlet. It cannot read other Servlet <init-param> data because <init-param> is written within <servlet> tag. What is ServletContext? On the contrary, ServletContext is global. The ServletContext object can be used by all the Servlets under execution in an application. Application comprises of many programs bundled together to achieve …

What is ServletContext interface? Read More »

What is ServletConfig interface?

The needs of server-side programming are well thought and architectured by Servlet Designers. If a specific Servlet should be started with some default properties well-suited for certain job, the question is where the properties should be assigned. The properties may change seldom and each time the Servlet should be compiled and deployed is also another …

What is ServletConfig interface? Read More »

Can we have Servlet Constructor?

Yes, you can have as per rule. It is executed even before init(). Then why generally we avoid constructor in Servlets. First let us write one simple example and see it is true or not; then we will go into details. Example on Servlet Constructor import javax.servlet.ServletException; import javax.servlet.http.*; import java.io.*; public class ConstructorServlet extends …

Can we have Servlet Constructor? Read More »

HttpServletRequest vs HttpServletResponse

Both HttpServletRequest and HttpServletResponse are inevitable in each Servlet, the Programmer write. Both exist in Servlet code as parameters to service() method. Even a Novice should be acquainted of these two interfaces. List of Differences HttpServletRequest vs HttpServletResponse Both are interfaces from javax.servlet.http package. They are derived from ServletRequest and ServletResponse interfaces. Both objects are …

HttpServletRequest vs HttpServletResponse Read More »

What is MIME type in Servlets?

1. What is MIME? MIME is an abbreviation for "Multipurpose Internet Mail Extensions". At the start, email was intended to transport for textual message only and later added attachments etc. These attachments include different files of various formats like images, text files, video and audio etc. To name these extra attachments MIME was introduced. Browsers …

What is MIME type in Servlets? Read More »

setContentType() Method Example

We know when a Servlet is loaded, the Servlet container creates an object of Servlet, calls service() method, creates an object of HttpServletRequest and also an object of HttpServletResponse and passes these objects to service() method. The job of HttpServletResponse (referred as response object in this discussion) is to pass data required by the client …

setContentType() Method Example Read More »

Auto Page Refresh Servlets with setHeader()

What is Page Refresh Servlets? Sometimes, user requires latest information on Cricket score or latest Share prices etc. where he is required to refresh the page, say by typing F5 key. To make user’s job easier, Servlet comes with setHeader("refresh", "5") method. With this method, the same Servlet is called for every 5 seconds once …

Auto Page Refresh Servlets with setHeader() Read More »

ServletResponse vs HttpServletResponse

When the client sends a request to the Web server, the server loads the concerned Servlet and executes the service() method. In the process of execution, the container creates objects of ServletRequest and ServletResponse and passes them to the service() method. This is discussed in First Example – Login Screen Validation. ServletResponse vs HttpServletResponse Observe, …

ServletResponse vs HttpServletResponse Read More »

ServletRequest vs HttpServletRequest

When the client clicks the submit button and sends a request to the server to invoke some Servlet (by giving the alias name of Servlet), the Servlet container loads the servlet and calls the service() method. The container also creates objects of ServeltRequest and ServletResponse and passes them to service() method. The ServletRequest receives the …

ServletRequest vs HttpServletRequest Read More »

Servlet vs GenericServlet vs HttpServlet

What is Servlet vs GenericServlet vs HttpServlet? Servlets are platform-independent server-side components, being written in Java. Before going for differences, first let us see how the three Servlet, GenericServlet, HttpServlet are related, their signatures and also at the end similarities. See how to write a Servlet. public class Validation extends HttpServlet To write a servlet, …

Servlet vs GenericServlet vs HttpServlet Read More »