Containers
______________________________________________________
A container runs and controls the servlets.
A full J2EE application server must have both a web container and an EJB container.
When a request is received by the webserver and needs to access a servlet, the webserver hands the
request to the servlet-helper app : the container. Then the container hands the request to the servlet
itself.
Role
- Match the request URL to a specific servlet;
- Creates request and response objects used to get informations from the client and send back informations to him;
- Creates the thread for the servlet;
- Calls the servlet’s service() method, passing request and response objects as parameters;
- service() method will call the doXxx() method of the servlet depending on request type;
- Get the response object from the finished service() method and converts it to an HTTP response;
- Destroys request and response objects;
- Sends back response to the webserver
Capabilities of containers
Containers provide :
- Communications support : handles communication between the servlets and the webserver
- Lifecycle management : controls life and death of servlets, class loading, instantiation, initialization, invocation the servlets’ methods, and making servlet instances eligible for GC
- Multithreading support : Automatically creates a new thread for every servlet request received. When the Servlet service() method completes, the thread dies.
- Declarative security : manages the security inside the XML deployment descriptor file. Security can be configured and changed only by modifying this file.
- JSP support : Manages the JSPs.
URL to servlet mapping
The servlet container uses the deployment descriptor to map URL to servlets. Two DD elements
are used to achieve this :
<servlet> : maps internal name to fully qualified class name;
<servlet-mapping> : maps internal name to public URL name.
Model-View-Controller (MVC) Design
MVC does not only separates the Business Logic from the presentation, the Business Logic doesn’t
even know there is a presentation.
MVC : separate Business Logic (model) and the presentation, then put something between them toconnect them (controler), so the business can become a real re-usable code, and the presentation layer can be modified/changed at will.
No comments:
Post a Comment