Features of javax. servlet APIs

Source: Internet
Author: User
Tags object serialization

Servlet APIs have been supported by most Java-based Web servers, which means that when using servletapi, Java can inherit many advantages: not only does the Code not contain memory vulnerabilities and hard-to-find pointer bugs, it can also run on platforms provided by many different servers.
1. Main Functions of javax. servlet
Servlet uses a common programming model for receiving requests and generating responses. This model uses a series of distributed system programming toolboxes, from remote process calls to sending HTTP requests to Web servers.
Servlet programming is actually very simple, mainly to implement a servlet interface, for example:

Import javax. servlet .*;

Public class myservlet extends genericservlet {
Public void Service (
Servletrequest request;
Servletrespose response;
) Throws servletexception, ioexception
{
......
}
}
The request and Response parameters can be operated in the service method. The data sent by the client is encapsulated, access to the parameters is provided, and various statuses (including error information) can be reported by the servlet. Generally, servlet obtains most parameters through the input stream and sends their responses using the output stream.
Servletinputstream in = request. getinputstream ();
Servletoutputstream out = response. getoutputstream ();
These input/output streams can use different formats of data. For example, Applet and servlet can use Object serialization to exchange data, or HTML and image formats.
2. servlet and its environment
Servlet is a Java object that consists of specific instance data. This means that the servlet being executed is an independent application running inside the server.
During initialization, the servlet accesses some specific servlet configuration data, which allows different instances of the same servlet class to be initialized with different data and managed as servlets of different names. The data provided during initialization includes where each instance stores its own status.
Servlet can also use servletcontext objects to interact with their own environments.
3. usage mode
Servlet can use the following modes. However, the difference is that all server environments support all these modes:
(1) the basic mode is based on the request/response protocol.
(2) The server can use the filter chain to link Multiple servlets.
(3) servlet can support specific protocols, such as HTTP.
(4) In HTTP-based applications, servlet is a complete (and more efficient) alternative to CGI-based extensions.
(5) In HTTP-based applications, servlet can also be used as an HTML server to include dynamically generated Web documents.
4. Main servlet Methods
Servlet is always loaded dynamically, although the server usually provides a management option to force loading and initializing a specific servlet at server startup. Servlets are loaded using common Java-class loading tools, which means they can be loaded from remote directories (for example, trusted http: // user/servlet Directories), which is as easy as using a local file system, this method improves the flexibility of the system structure and makes it easier and faster to publish services on the network.
After a servlet is loaded, its lifecycle involves three main methods:
(1) servlet is activated by the server by calling the init method. If the servlet developer needs it, they can execute some internal settings so that each request does not need to be set once, for example, initializing sessions of other network services or accessing the data they own (stored in databases or files ).
(2) After initialization, the servlet processes many requests and generates a service call for each customer request. These requests may be in parallel, which allows the servlet to adjust the behavior of multiple customers, the static status of the class can be used to share data in requests.
(3) The servlet object will always process the request, unless the server calls the destroy method to explicitly close the servlet, the servlet class is still a valid garbage collector.
5. Security
Servlet must access the information of the customer sending the request. When using security protocols, such as SSL, the servlet can authenticate the identity of the other party quite reliably.
Servlet has most of the advantages of Java, such as not allowing unauthorized access to memory and types. In this way, the defective servlet will not cause service crash, which often occurs in the server environments of most C languages.

Unlike other Server Extension APIs, java servlet provides powerful security policy support because all Java environments provide a security manager, it can be used to control whether an operation is allowed, such as access to network files. By default, all servlets mounted over the network are untrusted and do not perform operations such as accessing network services or local files. The servlet created in the Java Web server or locally managed by the server is completely trusted and granted with all permissions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.