Thread safety of the servlet »



Q) How to ensure the thread safety of the servlet?
Rep)
1) It is better to avoid instance variables & static variables in a servlet class
2) If the instance variable reference to a threadsage object then there will be no problem
3) If all Instance variables refers to an object that is not thread safe then we [...]

Can we provide a constructor in the servlet class »



Rep) As the Web Container uses newInstance() method for creating the servlet object,If requiered we can provide a zero arguent constructor

How the Web Container creates a servlet object »



Rep) Web Container reads the name of the servlet class from web.xml and uses Class.forName() method to load the servlet class and it calls the newInstance() method to create the servlet Object.

Servlet Important Questions »



Q)  What is the servlet?
A) Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.
Servlets are to servers what applets are to browsers. Unlike applets, however, [...]