Java servlet Technology

Source: Internet
Author: User

when the web was first used to deliver services, the service provider was aware of the need for dynamic content. Applets are one of the first attempts to achieve this goal, focusing on using the client platform to deliver a dynamic user experience. At the same time, developers are also investigating how to use the server platform to achieve this goal. At the outset, the public Gateway Interface (Common Gateway Interface, CGI) script is the main technology for generating dynamic content. Although widely used, CGI scripting techniques have many drawbacks, including platform dependencies and lack of extensibility. To avoid these limitations, Javaservlet technology emerged. It is able to provide dynamic, user-oriented content in a portable way to handle user requests.

a servlet is that Java programming language A class that is used to extend the performance of the server, which resides in applications that can be accessed through the request-response programming model. Although the servlet can respond to any type of request, it is usually used only to extend the application of the Web server. Javaservlet Technology defines an HTTP-specific servlet class for these applications.

The Javax.servlet and javax.servlet.http packages provide interfaces and classes for writing Servlets. All Servlets must implement the servlet Interface, which defines the life cycle approach.

When implementing a common service, you can use or extend the Genericservlet class provided by the Java Servlet API. the httpservlet class provides methods, such as Doget and dopost, to handle HTTP-specific services.

The life cycle of the servlet

Edit

a servlet 's life cycle is controlled by the container that deploys the servlet. When a request is mapped to a servlet, the container performs the following steps.

1. If an instance of a servlet does not exist, the Web container

A. Load the servlet class. B. Create an instance of a servlet class. C. Call init to initialize the servlet instance. The initialization process is described in the initialization servlet. 2. Call the service method, passing a request and response object. The service method is described in the authoring service method.

If the container is to be removed from the servlet, call the servlet's Destroy method to end the servlet. The end process will be discussed in the end Serlvet.

Handling Servlet life Cycle Events

in the servlet lifecycle, users can detect and react to events by defining listener objects. The method that invokes the object when the life cycle event occurs. To use these listener objects, the user must define the Listener class and specify the appropriate listener class.

Defining listener classes You can define the listener class as an implementation of a listener interface. The servlet life cycle Events list the events that can be detected and the corresponding interfaces that must be implemented. When invoking a listener method, the method is passed an event that contains the appropriate information for the event. For example, a httpsessionevent event is passed to the method in the Httpsessionlistener interface, which contains a httpsession.

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/84/38/wKiom1eIlriTvEL-AASoe6eztbs271.jpg-wh_500x0-wm_3 -wmp_4-s_2694354294.jpg "title=" Weibo copy of a replica of a Hyatt copy. jpg "alt=" wkiom1eilritvel-aasoe6eztbs271.jpg-wh_50 "/>

Chuang Yue (Shenzhen) Investment Management Co., Ltd.

Cheer for Growth

: Creajoyyojoy

Weibo: Http://weibo.com/CreajoyYOJOY

Official website: http://www.creajoyvc.com/

Contact & submission: [Email protected]

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/84/38/wKioL1eIlvagZVzCAARBMyWRVOU723.jpg-wh_500x0-wm_3 -wmp_4-s_2514578546.jpg "title=" "alt=" Wkiol1eilvagzvzcaarbmywrvou723.jpg-wh_50 "/>


Java servlet Technology

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.