Servlets Interview Questions and Answers
Ques 21. Why don't we write a constructor in a servlet?
Ans. Container writes a no argument constructor for our servlet.
Is it helpful?
Add Comment
View Comments
Ques 22. When we don't write any constructor for the servlet, how does container create an instance of servlet?
Ans. Container creates instance of servlet by calling Class.forName(className).newInstance().
Is it helpful?
Add Comment
View Comments
Ques 23. 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?
Ans. 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.
Is it helpful?
Add Comment
View Comments
Ques 24. What is the difference between callling a RequestDispatcher using ServletRequest and ServletContext?
Ans. >We can give relative URL when we use ServletRequest and not while using ServletContext.
Is it helpful?
Add Comment
View Comments
Ques 25. 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()?
Ans. Since ServletRequest has the current request path to evaluae the relative path while ServletContext does not.
Is it helpful?
Add Comment
View Comments
Most helpful rated by users: