1.What is an Applet container?
– It is a container to manage the execution of applets.
– It consists of a web browser and a Java plug-in running together on the client.
What are the functions of Servlet container?
The main functions of Servlet container are:
1. Lifecycle management : Managing the lifecycle events of a servlet lik class loading, instantiation, initialization, service, and making servlet instances eligible for garbage collection.
2. Communication support : Handling the communication between servlet and Web server.
3. Multithreading support : Automatically creating a new thread for every servlet request and finishing it when the Servlet service() method is over.
4. Declarative security : Managing the security inside the XML deployment descriptor file.
5. JSP support : Converting JSPs to servlets and maintaining them.
What is Servlet Chaining?
– It is a method in which the output of one servlet is piped into the next servlet.
– It is the last servlet in the chain that provides the output to the Web browser.
2.What is the difference between callling a RequestDispatcher using ServletRequest and ServletContext?
– While using a ServletRequest a relative URL can be provided, which can not be done while using ServletContext.
3.How would you create deadlock on your servlet?
– Calling a doPost() method inside doGet() and doGet()method inside doPost() wouleate a deadlock for a servlet.
4.What are the uses of Servlet?
The important used of HTTP Servlets are:
– Storage and processing of data submitted by an HTML form.
– Providing dynamic content to the client for example outputting the result of a query.
– Improving the system performance by handling multiple requests at a time.
– Managing state information on top of the stateless HTTP.
5.Why is HttpServlet declared abstract?
– The default implementations of the main service methods can not do anything and need to be overridden. This calls of the HttpServlet class to be declared as abstract.
– With its use the developers do not need to implement all the service methods.
6.Differentiate between GET and POST.
– When you use GET, the entire form submission gets encapsulated in one URL. The query length is limited to 260 characters, not secure, faster, quick and easy.
– When you use POST your name/value pairs inside the body of the HTTP request, which makes a cleaner URL. It imposes no size limitations on the form’s output. It is used to send a large amount of data to the server to be processed. It is comparatively more versatile and secure.
7.When should you prefer to use doGet() over doPost()?
GET is preferred over POST in most of the situations except for the following:
– When the data is sensitive.
– When the data is greater than 1024 characters.
8.When using servlets to build the HTML, you build a DOCTYPE line, why do you do that?
– Building a DOCTYPE line informs the HTML validators about the version of HTML you are using. This tells them the specification against which your document should be checked.
– These validators work as valuable debuggers which help you catch the HTML syntax errors.
9.Why is a constructor needed in a servlet even if we use the init method?
– Although the init method of the servlet initializes it, a constructor instantiates it.
– A developer might never explicitly call the servlet’s constructor but a container uses it to create an instance of the servlet.
10.What is lazy loading?
The servlets are not initialized by the container from the start. It happens when the servlet is requested for the first time. This is called lazy loading.