A powerful feature of Java Servlet APIS is its ability to easily process form data. Unlike the search for environment variables in traditional CGI development, you can use Servlets to access forms and query string data by calling Java methods. Let's take a look at how it works. You can download the sample code here.
Load Servlet
When a Servlet is loaded, the Servlet engine calls the Servlet init method. This method is called only once when the Servlet is loaded, and the configuration data is passed in the form of an instance of the ServletConfig class. The ServletConfig object contains information about the Servlet engine and Servlet runtime environment.
The ServletConfig object exposes initialization data to the Web application operated by the Servlet. Use the getInitParamete (StringparamName) method to access this data, as shown in Listing.
Before destruction
The Servlet class exposes a method called destroy, which is called by the Servlet engine when the Servlet is uninstalled normally. This method is called when all the Servlet threads are uninstalled or the specified time is exceeded. It is used to save Servlet or clear resources. For details, see Listing B.