A servlet, called a server-side applet, is a program that runs on the server side to process response client requests. Ability to handle get, POST, PUT, delete requests from clients. Only get and post are commonly used, and the Doget and Dopost methods need to be overridden in the servlet. Most of the time the servlet responds to all requests in the same way, so only the service method needs to be rewritten.
The Init method in the servlet is used to initialize the servlet resource, and the Destroy method is used to destroy the servlet instance. You usually do not have to write it yourself, if you write it, you need to define the initialization operation in Init, and call the Super.init (config) method on the first line of the method.
Although the JSP can be transferred to a servlet, there is no built-in object in the servlet and needs to be created. For the static HTML part of the JSP, the output stream needs to be output row by line. The service method inside the common servlet class is equivalent to the _jspservice () method of the servlet generated by the JSP.
There are two ways to configure a servlet, one is to use @webservlet, and the other is to take advantage of an XML file. XML, the name and URL of the servlet need to be developed. Examples are as follows:
"Servlet"
" servlet-name" Loginservlet "/servlet-name"
"Servlet-class" com. Loginservlet (package name, class name) "/servlet-class"
"/servlet"
"Servlet-mapping"
" servlet-name" Loginservlet "/servlet-name"
" Url-pattern"/loginservlet "/url-pattern"
"/servlet-mapping"
The contents of " servlet-name" "/servlet-name" in the label "Servlet" and "servlet-mapping" must be consistent
The explanation of servlet and servletmapping
All right, Sina directly turned around, ugly title number ...
This article from "Fingertip Light Fly" blog, declined reprint!
JSP Note--6.servlet Introduction