• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Servlet Interview Questions Answers

Question - 1 : - When using servlets to build the HTML, you build a DOCTYPE line, why do you do that?

Answer - 1 : - I know all major browsers ignore it even though the HTML 3.2 and 4.0 specifications require it. But building a DOCTYPE line tells HTML validators which version of HTML you are using so they know which specification to check your document against. These validators are valuable debugging services, helping you catch HTML syntax errors.

Question - 2 : - Can we  use the constructor, instead of init(), to initialize servlet?

Answer - 2 : - Yes , of course you can use the constructor instead of init(). There's nothing to stop you. But you shouldn't. The original reason for init() was that ancient versions of Java couldn't dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won't have access to a ServletConfig or ServletContext.

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

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

Question - 4 : - What is Servlet?

Answer - 4 : - A servlet is a Java technology-based Web component, managed by a container called servlet container or servlet engine, that generates dynamic content and interacts with web clients via a request\/response paradigm.

Question - 5 : - Which interface must be implemented by all servlets?

Answer - 5 : - Servlet interface.

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

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

Question - 7 : - What is new in ServletRequest interface ? (Servlet 2.4)

Answer - 7 : - The following methods have been added to ServletRequest 2.4 version: public int getRemotePort() public java.lang.String getLocalName() public java.lang.String getLocalAddr() public int getLocalPort()

Question - 8 : - Why is it that we can't give relative URL's when using ServletContext.getRequestDispatcher() when we can use the same while calling ServletRequest.getRequestDispatcher()?

Answer - 8 : - Since ServletRequest has the current request path to evaluae the relative path while ServletContext does not.

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

Answer - 9 : - 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 - 10 : - Why don't we write a constructor in a servlet?

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

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners