JBuilder2005 servlet Development Essentials

Source: Internet
Author: User

A servlet can create protocols, platform-independent web applications, applets run in the browser's JRE, and the servlet runs in the servlet container of the Web application server, and the servlet does not have a user graphical interface. Servlet and the Web application server's servlet container interact to receive requests to return responses. The request was first processed by the Web application server's servlet container and passed to Servlet,servlet to return the response to the client via the Web application server. A client program can use any language development that can send a request to a Web application server.

The biggest advantage of the servlet is its high performance, the servlet uses a very different way of running with CGI, first the servlet loads and resides in memory at the first initialization, and then runs directly from memory, and second, the servlet works in single instance multithreading by default , when a new request arrives, the servlet instance opens the request for a new thread service.

Servlet Architecture and Thread safety

All servlet implementations Javax.servlet.Servlet interfaces directly or indirectly, which specify how the servlet communicates with the servlet container, and also define the lifecycle of the servlet. Genericservlet is a protocol-independent universal Servlet,httpservlet that is a servlet,web application developed specifically for HTTP protocols that directly inherits HttpServlet. The inheritance system of its class is shown in the following illustration:

Figure 1 The class inheritance system of the servlet

The Javax.servlet.Servlet interface includes 3 ways to control the servlet lifecycle, respectively:

init (servletconfig config) method

When the servlet initializes, the init () method is called to perform the work of initializing the servlet, and the Init () method is invoked only once. When the servlet is initialized, it enters a ready state, ready to respond to client requests.

Service (ServletRequest req, Servletresponse resp) method

The servlet container invokes the service () method to process the request and return the response. ServletRequest and Servletresponse are passed as incoming parameters to the service (), ServletRequest encapsulates the requested information and Servletresponse encapsulates the response information.

Destroy () method

The servlet container can uninstall the servlet at any time, at which point Destory () is invoked, where you can release the resources that the servlet occupies.

The classes in the Javax.servlet.http package are used to support HTTP protocols and create HTML Web pages. The HTTP protocol is based on the request/response mode of operation, and these HTTP requests include:

Get

POST

Put

DELETE

Head

TRACE

CONNECT

OPTIONS

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.