servlet work steps

servlet work steps

Key Technology + xml parsing reflection

1. Load class

1. servlet path taken in the url

2. Find the value of url-pattern in web.xml inside, it reported 404 not found error.

3. Locate the find to the corresponding servlet-name based on the value of url-pattern

The servlet-name found servlet-class corresponding to the class to find

5. reflected by Class cl = Class.forName ( "servlet-class A value of")

2. Create a servlet objects

Object obj = cl.newInstance (); // create an object by reflection

3. Call init () method

Method m1 = cl.getMethod ( "init"); // performing the method by reflection

m1.invoke(obj);

4. Call service () method

Method m2 = cl.getMethod ( "service", servletrequest.class, servletresponse.class); // performing the method by reflection

m2.invoke(obj,request,response);

5. Call destroy () method

Method m3 = cl.getMethod ( "destory"); // reflection performed by the method

m3.invoke(obj);

Guess you like

Origin www.cnblogs.com/chenguosong/p/12468097.html