• +91 9971497814
  • info@interviewmaterial.com

Servlet Interview Questions Answers

Question 1 : Why don't we write a constructor in a servlet?

Answer 1 : Container writes a no argument constructor for our servlet.

Question 2 : What mechanisms are used by a Servlet Container to maintain session information?

Answer 2 : Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information

Question 3 : How can I send user authentication information while making URL Connection?

Answer 3 : You'll want to use HttpURLConnection.setRequestProperty and set all the appropriate headers to HTTP authorization.

Question 4 : Request parameter How to find whether a parameter exists in the request object?

Answer 4 : 1.boolean hasFoo = !(request.getParameter("foo") == null || request.getParameter("foo").equals("")); 2. boolean hasParameter = request.getParameterMap().contains(theParameter); (which works in Servlet 2.3+)

Question 5 : Given the request path below, which are context path, servlet path and path info?

Answer 5 : /bookstore/education/index.html context path: /bookstore servlet path: /education path info: /index.html

Question 6 : What is filter? Can filter be used as request or response?

Answer 6 : A filter is a reusable piece of code that can transform the content of HTTP requests,responses, and header information. Filters do not generally create a response or respond to a request as servlets do, rather they modify or adapt the requests for a resource, and modify or adapt responses from a resource.

Question 7 : If a servlet is not properly initialized, what exception may be thrown?

Answer 7 : During initialization or service of a request, the servlet instance can throw an UnavailableException or a ServletException.

Question 8 : When a client request is sent to the servlet container, how does the container choose which servlet to invoke?

Answer 8 : The servlet container determines which servlet to invoke based on the configuration of its servlets, and calls it with objects representing the request and response.

Question 9 : What is servlet container?

Answer 9 : The servlet container is a part of a Web server or application server that provides the network services over which requests and responses are sent, decodes MIME-based requests, and formats MIME-based responses. A servlet container also contains and manages servlets through their lifecycle.

Question 10 : Why is Servlet so popular?

Answer 10 : Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web server.

Servlet Contributors


Share your email for latest updates


Our partners