Oct 19

Servlets Tutorial 4 : Explain life cycle of Servlets?

Number of View: 32

Servlets follow three phase life cycle initialization,service and destruction.

1) init() method :

1) init() method : init method is called when the servlet is first created.

2) init() method is called exactly once after the instantiating Servlet.

3) init() method is used to write initialization code such as loading database drivers and initialization values so on.

4) When invoking this method servlet container passes a Servlet-Config.

5) One of the most important and common task that init() method performs is reading server specific initialization parameters.

6) The init method is important  because the servlet container passes a ServletConfig object, which contains the configuration values given in the web.xml file.

Signature : public void init(ServletConfig servletConfig) throws ServletException

init() method can throw servlet exception.When init() method throws Servlet exception servlet container does not executes service() method.

servletException is also thrown when the method does  not return with in the time period.

Continue reading

Oct 19

Servlets Tutorial 2 : Explain Servlet api and its methods?

Number of View: 27

Explain Servlet api and its methods ?

1) All Servlets must  implement javax.servlet.Servlet interface either directly or indirectly.

2) Servlet container will create an instance of Servlet class and uses it to handle incoming requests.

3) Servlet interface defines methods that all servlets must implement.

4) Servlet class defines a contract between Servlet and Servlet container.

Continue reading

Sep 08

Explain Final parameters with example in java?

Number of View: 104

Final Parameters:

1) Formal paramters can be declared as final .

2) A formal parameter is initialized automatically with the value of the actual parameter when the method or the constructor is invoked.

3) Therefore final formal parameter value cannot be changed inside the method’s or the constructor’s body. Continue reading