Select Category 
Servlet Interview Questions Answers Exammaterial
Given the request path below, which are context path, servlet path and path info?
Servlet Interview Questions Answers Exammaterial

/bookstore/education/index.html

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

Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet In
Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servlet Interview Questions Answers Exammaterial Servl
 

Servlet Interview Questions Answers

Servlet Interview Question - 16 : -

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

Servlet Interview Answer - 16 : -

/bookstore/education/index.html

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

 

Servlet Interview Question - 17 : -

Why don't we write a constructor in a servlet?

Servlet Interview Answer - 17 : -

Container writes a no argument constructor for our servlet.
 

Servlet Interview Question - 18 : -

What is servlet mapping?

Servlet Interview Answer - 18 : -

The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to servlets.
 

Servlet Interview Question - 19 : -

What is the difference between callling a RequestDispatcher using ServletRequest and ServletContext?

Servlet Interview Answer - 19 : -

We can give relative URL when we use ServletRequest and not while using ServletContext.
 

Servlet Interview Question - 20 : -

Once the destroy() method is called by the container, will the servlet be immediately destroyed? What happens to the tasks(threads) that the servlet might be executing at that time?

Servlet Interview Answer - 20 : -

Yes, but Before calling the destroy() method, the servlet container waits for the remaining threads that are executing the servlet’s service() method to finish.
 

Servlet Interview Question - 21 : -

What is Servlet?

Servlet Interview Answer - 21 : -

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.
 

Servlet Interview Question - 22 : -

What is servlet container?

Servlet Interview Answer - 22 : -

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.
 

Servlet Interview Question - 23 : -

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

Servlet Interview Answer - 23 : -

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

Servlet Interview Question - 24 : -

Explain the life cycle of Servlet.

Servlet Interview Answer - 24 : -

Loaded(by the container for first request or on start up if config file suggests load-on-startup), initialized( using init()), service(service() or doGet() or doPost()..), destroy(destroy()) and unloaded.
 

Servlet Interview Question - 25 : -

What is servlet context ?

Servlet Interview Answer - 25 : -

The servlet context is an object that contains a servlet's view of the Web application within which the servlet is running. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use. (answer supplied by Sun's tutorial).