Javaweb02_servlet and Web Containers

Source: Internet
Author: User

Javaweb02_servlet and Web container OSI Reference Model

Application layer, Presentation layer, Session Layer (tcp/ip: Application layer – program, http Layer)
Transport Layer (tcp/ip: Transport layer--tcp/udp Protocol)
Network layer (tcp/ip: Network layer--ip, Encapsulation)
Data Link layer, Physical layer (tcp/ip: physical layer-lowest level, network interface, ethernet, ATM, token ring, etc.)

Client

Proactively create a socket ();
Connect to the specified computer port connect ();
Writes the information to the socket () send ();
Socket () Off

Server

Passive creation of a socket ();
Binding port number and listening port
Receive a request from a user
Remove a character from the socket
Close connection

http

Hypertext Transfer Protocol
Rules of computer network communication
Port: 80
Is the protocol that connects the client and the server (following the TCP/IP Model)
HTTP is in the Application layer, application protocol
Features: ① Stateless Protocol (no Persistent connection is established, disconnect after communication Ends)
② follows the request response Model: all communications are in the request response model

HTTP request:

Request Line: method of request, HTTP version, address of the requesting server, etc.
Request Header: meta-information for HTTP header delivery
Blank line: send carriage return for regression that splits the contents of the request header and the body of the message
Message Body: Post submission puts the data transmitted by the client in the message body, the browser does not see the content

HTTP response

Status Line: HTTP version and status code (E.G. 200, 404, 505, etc.)
Response Header: Description of the content, length, and some information about the server
Blank line: send carriage return and regression, split response header and message body
Message body: The content of the response

The process of HTTP execution

1. Client and Server connection established
2. The client sends the request
3. Server Response Information
4. The server closes the connection and the client resolves the response content

Servlets and Web Containers

Function: used to solve the problem of CGI multi-process (the first time a user requests a servlet, the server produces a process, each subsequent access to the same servlet is the creation of a new thread)

Four features of Servlets:
1. General Java code (new api)
2. Does not belong to the j2se, belongs to the individual specification
3. Expansion of the standard class (httpservlet)
4. No main () method (container to Invoke)

Tasks for Servlets:
1. Read explicit, implicit data
2. Generate results
3. Send data

What is a web container:
Simply put, the Web container is responsible for managing and running the servlet

Relationship between a container and a servlet

1. Communication Support: using the method provided by the container, the servlet and the container can be easily communicated without the need to establish server-socket, listening ports, streams, etc., only need the Servlet's business logic
2. Lifecycle Management: The servlet has a lifecycle, the container automatically loads the class, invokes the method, destroys the servlet
3. Multithreading: The container creates a new Java thread for each requested user, runs out of HTTP request responses, and the thread automatically destroys
4.jsp support: containers automatically translate JSP into Java code
5. Handling Security: Javaweb programs need to implement security controls to limit the resources that users can access

servlet specification

Container/server:
1.TOMCAT: free, small program, easy to operate and deploy, open source
2.JBOSS:EJB container, also available as a servlet container
3.weblogic: large systems or distributed Web sites
4.IIS: Microsoft launches a server that can be used to run. net programs directly
5.apache:apache company, In addition to tomcat, also launched a payment server

Tomcat's directory Structure

Bin: Store script files, including start, close Tomcat
Conf: storing tomcat various configuration files
Lib: a jar package available for running
Logs:tomcat startup, shutdown, and run log files
Temp: temp File
Webapps: Storage of developed applications
Work tomcat: working directory, JSP translated code

Javawen Project Catalogue

Project name
Src: Store Code
Webroot:meta-inf (all Content clients cannot access), web-inf (lib:jar package; Web. xml: project configuration file; classes: compiled Java code)

Summarize:

1.http protocol is the rule of computer network communication
2.web server does not support server-side Dynamic Web pages
3.CGI and servlet are implementations of web server-assisted applications
4.CGI memory Consumption (multi-process)
5.servlet and container mates handle requests and responses
6. The container is responsible for supporting Servlet,servlet to handle the business Process.
7. What is a servlet? A servlet is an effective and powerful solution for creating dynamic content on the Web by running Java programs on a Web server or application server!!

Javaweb02_servlet and Web Containers

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.