Java Servlets Question and Answers

1. What are Servlets?
 
  • Servlets are small program which execute on the web server.
  • They run under web server environment exploiting the functionalities of the web server.
 
Your Name Your Email-ID
Your Answer
2. What are the advantages of Servlets over CGI?
 
  • In CGI for every request there is a new process started which is quiet an overhead.
  • In CGI if there are 1000 request then CGI program is loaded in memory while in servlets there are 1000 thread and only one copy of the servlet class.
 
Your Name Your Email-ID
Your Answer
3. What is the difference between ServletContext and ServletConfig?
 
  • ServletConfig contains data from the servlet in the form of name and value pairs.
  • Using the ServletConfig we get reference to the ServletContext object.
  • ServletContext gives the servlet access to information about its runtime environment such as web server logging facilities, version info, URL details, web server attributes etc.
 
Your Name Your Email-ID
Your Answer
4. Can we explicitly destroy a servlet object?
 
  • No, we cannot destroy a servlet explicitly it's all done by the container.
  • Even if you try calling the destroy method container does not respond to it.
 
Your Name Your Email-ID
Your Answer
1234567891011 Page 1 of 11