Do you know how Java Servlets work?
Java servlets are executed by web containers.
I know that much. Web containers also run JSP pages for Java.
The Web container instantiates or starts the servlets. It also starts new threads to handle the request.
OK, but what about how the servlets work?
The container will create several threads to handle the requests to the servlet. Click on a link or some other action, and Java sends a request for a servlet to the web container.
Then what?
The web container finds the servlet per the information in a deployment descriptor before creating two servlets; one is for the request, the other for the response.
So the container creates servlets.
Then the web container allocates a thread and starts the service method in the servlet. It then passes on all request and response objects.
How does the servlet know what to do?
The service method decides which servlet method to use, based on the request method in the web container.
So the parent object is passing down details and methods to the servlet.
The servlet uses a response object to generate a response sent back to the client. After it is done with its response, the service method completes and the thread dies.
That closes the thread. What about the objects the servlet created?
Java's garbage collection close the request and response objects created by the servlet.
Garbage collection? It sounds like we need more of that in programming in general.
The garbage collection is only for threads and objects created by Java objects and methods, no code modules themselves. Java is just as prone to GIGO as everything else.
What is GIGO?
Garbage in, garbage out.
Oh, that's not just programming. I think it applies to a few fast food places near me, too.
Tell me which ones so I never eat there.
Ещё видео!