JAVA Servlets Profile

 
JAVA Servlets Why is superior to the traditional CGI
JAVA Servlets than the traditional CGI CGI or other similar alternative technologies, more efficient, more convenient to use, more powerful, more compact and also cheaper:
1)  Efficiency, the traditional CGI for each HTTP request to create a new process. If a CGI program is a very fast implementation of the operation, the time to open the process may take up most of execution time. On the JAVA Servlets, in the JAVA virtual machine, each request from a 'small' JAVA threads (thread) response, not a `big` operating system process. Similarly, if the traditional CGI with a CGI-N procedures at the same time request, the CGI program code will be imported into memory N times. JAVA Servlets have N threads, but only a JAVA Servlets CLASS a copy. At the same time JAVA Servlets more than CGI optimization, as calculated in advance, open database connectivity.
2)  Convenient, JAVA Servlets can automatically decode and paste the HTML form data, the first reading and set up HTTP, handling COOKIES, tracking SESSIONS, and other large functions.
3) powerful features, JAVA Servlets can be very easy to achieve the CGI is impossible or very difficult matters. JAVA Servlets and servers direct communication with the CGI is not.
4)  JAVA Servlets can share data between, it is easy to achieve, such as database connection pool. It can facilitate the realization of management from REQUEST to REQUEST request, to simplify SESSION and access to the previous page. And poor communication between the CGI, as each of the CGI programs are beginning to call a new process, called communication usually through the documents, thus very slow. The same server on the different procedures for communication between the CGI is quite troublesome.
5)  Call time: CGI process is running as a separate process, usually called a long time, the indirect costs of each call to occur. In explanation of the use of the time called for a longer time. The memory of the servlet can very quickly to load.
 6)  Security: CGI version has some obvious security weaknesses. Even with the latest standards and PERL language, and so on, the system has no basic security framework, and in fact rely on a set of rules. The java definition of a complete security mechanisms, including ssl, ca authentication, security policy norms.
7)  Compact, JAVA Servlets use JAVA preparation, follow a standard API. It directly or through plug-in almost all WEB server running on.
8)  Prices are low, it is clear that many are FREE.
 
Servlet some of the scope of application:

1)to deal with HTML form: HTTP have POSTed data, including the sale and purchase orders or credit card data. Therefore servlet can become part of the order processing system, and product inventory database to work together, and perhaps can be used in online payment systems.
2)allow people to the cooperation between: a servlet to handle complicated by a number of requests they can use in such a meeting, such as online synchronous request support systems.
3)transferred to the request: Servlet request to be transferred to other servers and servlets. This allows the same content in the mirror a few server load balancing. In accordance with the mandate of the type or organization can be allowed to be used in a number of logical servers on the server.
4)servlet writers can work together between the definition of the activation of agents, each agent is a servlet, but agents were able to send data between them.
 
Servlet structure

    In specific master servlet, must understand the language of java. Below are based on your understanding of java on the basis of the Servlet API is the most important Servlet interface. All the servlets implement (implementation) this interface, a variety of ways: either directly or through expansion of class (class) the implementation of it, If HttpServlet. This arrangement provides servlet Servlet interface with the client contact method. Servlet writers in their development process to provide more servlet some or all of such methods.
    When a servlet to receive calls from the client's request, it receives two targets: one is ServletRequest, another is ServletResponse. ServletRequest this broad category from the server, the link between the federation and the general category ServletResponse from servlet to return to the client's contact .
     ServletRequest interface to access such information as sent by the client on the names of clients in the correct use of the agreement, a request and receive requests for remote server host name. It also provides access to the data flow servlet, ServletInputStream, these data are Client invoked the use of HTTP POST and PUT methods of submission. ServletRequest a sub-category allows servlet of the agreement for more information. For example: HttpServletRequest include access to HTTP-specific information the head of the method.
     ServletResponse interface is the corresponding client servlet method. It allows servlet set content length and response to the mime type, and to provide the output stream, ServletOutputStream, writers can be returned through the corresponding data. ServletResponse sub-categories can be given more protocol-specific capacity Information. For example: HttpServletResponse include allowing servlet operation HTTP-specific information the head of the method.
     Of the above categories and interfaces constitutes a basic description of the Servlet framework. HTTP servlets have to provide some additional session-tracking capabilities of the method. Servlet writers can use the API there are others in the operation and maintenance of client servlet between the state .
 
Servlet life cycle
 
Servlet definition of the life cycle of a Servlet how to be loaded and initialized, as well as how it received the request, responding to requests and provide services.
     In the code, Servlet life cycle from javax.servlet.Servlet interface definition. All the Java Servlet to be directly or indirectly, to achieve javax.servlet.Servlet interface, so as to the Servlet Engine running on. Servlet Engine provides network Service, responding MIME request, running Servlet Container. javax.servlet.Servlet interface definition of a number of ways, in the Servlet life cycle, these methods will be at a given time in accordance with the order must be called. As shown in Figure :
 
Servlet how to be loaded (Load), were examples of (Instantiated)
Servlet Engine is responsible for loading and examples of Servlet, this process can Servlet Engine loading implementation, in response to a request Servlet implementation as well as in any time between the Executive.
Servlet how to initialize (Initialized)
     Servlet good load Servlet Engine, it must be initialized. Initialization Servlet database can be read from the initial data, JDBC Connection, or the establishment of other valuable resources used.
     In the initial stage, Init () method is called. This method is defined in javax.servlet.Serlet interface. Init () method to a Servlet profile (ServletConfig type) for the parameters. Servlet configuration targets to achieve by the Servlet Engine, which allows Servlet read some name-value of the parameter values. ServletConfig object can also accept a Servlet Servlet Context object.

Servlet how to deal with the request
     Servlet be initialized after, in response to the request of the state of readiness. Servlet each of the request by a representative of Servlet Request object. Servlet response to the client by a representative of Servlet Response object. When a client requests, Servlet Engine will ServletRequest and ServletResponse object article to a Servlet, the two objects as a parameter in the form of transmission methods Service. This method defined by the javax.servlet.Servlet by specific Servlet achieve.
     Servlet can also achieve ServletRequest and ServletResponse interface. ServletRequest Servlet interface allows access to client requests in the parameters, such as the form data, request information, protocol type, and so on. Servlet can flow from the ServletInputStream read request data. ServletResponse interface allows set Servlet response headers and status codes. Implementation of this interface can visit ServletOutputStream Servlet can flow to the return data to the client.
                                          
Servlet how to be released
Servlet Engine is not necessary in the Servlet life cycle of each over a period of time have maintained Servlet state. Servlet Engine can always free to use or release of Servlet. Therefore, you can not rely on Servlet class or its members store information. When a Servlet Servlet Engine judgement should be released when (for example, Engine ready to Shut down or in need of recovery resources), Engine must be able to release its Servlet are using any resources, and preserve the continuity of status information. These can call the Servlet destroy method. Servlet Engine in the release of a Servlet before, we must allow completion of the current examples of the service methods or wait until the timeout (if Engine definition of a timeout). When a Servlet Engine released after, Engine will not be able to further requests are forwarded to it, Engine must complete the release of the Servlet and marked as recyclable (for garbage collection).
In Servlet API is the most important Servlet interface. All Servlets implementation of the interface there are many ways: either directly or through extending its implementation of this class, such as HttpServlet. This Servlet interface to provide and arrange for the Servlet and client contact method. Servlet writers in their development process to provide more Servlet some or all of this method.
When a Servlet to receive calls from the client's request, it received two targets: one is ServletRequest, another is ServletResponse. ServletRequest class from the general federation, the link between the server and servletResponse class from the general to return to Servlet client contact.
    ServletRequest interface access to such information, such as by sending the parameters of the client name, the customer in the correct use of the agreement, have requested and received a request from the remote host server. It also provides access to the data flow Servlet, ServletInputStream, these data are cited in the use of client HTTP POST and PUT methods of submission. ServletRequest a sub-category allows for more Servlet the agreement of data.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值