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…

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…

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…

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…

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…

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…

ServletContext getResourceAsStream()

Using the method getResourceAsStream(), a Servlet can use any file on the system (or Web application in WEB-INF folder) and load it. To load, the Sevlet container does not need a traditional class loader. This method returns an object of InputStream that refers the file passed as parameter. The InputStream…

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

Output screenshot on Servlet…

Servlets vs CGI vs ASP

First let us know the earlier Web technologies, their drawbacks and how they are overcome in Servlets. Earlier to Servlets, the other Web technologies existed were CGI/PERL and ASP. Servlets vs CGI vs ASP I. CGI/PERL (Common Gateway Interface/Practical Extraction and Report Language) CGI/Perl is process based. For every request…

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…

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…

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…

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…

Servlets Tutorial Questions Answers

Servlets Tutorial What is Servlet? Servlet is a server-side Java program written as per Servlet API specifications invoked against a client request on the Web using HTTP protocol. Who executes a Servlet? Servlet is executed by a Web server. What is a Web server? Any server connected to Internet is…

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…

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()…

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…