Q) What are the general duties of a servlet?
Being a server side Java program, a servlet can do the following things in making the website dynamic.
1) Capturing the user input
2) Communicating with the database
3) Processing of data
4) Producing the response page
5) Handing over the response page to the web server
Q) What are the constituents of a servlet?
Servlet= Java code + HTMLcode
Q) Explain about the life cycle of a servlet?
Servlet life cycle is described through 3 life cycle methods and 4 phases.1. Instantiation phase
2. Initialization phase
3. Service phase
4. Destruction phase
Servlet container implicitly (automatically) calls these methods
Q) What is the general structure of a simple servlet?
public class RegistartionServlet implements Servlet
{
public void init(ServletConfigconfig)
{
//resources allocation Example: database connection creation, PreparedSatement creation
}
public void service(ServletRequestrequest,ServletResponse response)
{
//handling the client request(5 duties)
}
public void destroy()
{
//releasing the resources Example: closing the PreparedStatement and database connection
}
}
Q) Explain about Instantiation phase of a servlet?
• Servlet Container creating the instance of a user defined servlet is nothing but its instantiation phase.• Servlet Container loads the servlet class first and then creates its instance (object).
• Servlet class loading and instantiation happens dynamically.
• Whenever client request comes to a servlet for the first time, container creates the instance of the servlet.
• Instantiation happens only once in the life time of a servlet.
Comments
Post a Comment