Chapter One how the Java Web works

Source: Internet
Author: User

A: In this chapter we will learn the following content

"HTTP protocol principle

The principle of server-side web programming

"Servlet and Web container

The composition of the Java Web application

"Tomcat Introduction

One: 1.1 Parsing HTTP protocol

HTTP: Hypertext Transfer Protocol (hypertext Transfer Protocol)

HTTP is a stateless protocol that means that there is no need to establish a persistent connection between a Web browser and a Web server.

HTTP is in accordance with the request/response (Request/response) model.

HTTP Processing Flow:

1.1.1 Establishing a connection

This is true in Java's underlying code, but the browser has done it for us!

1.1.2 Send request information Once a TCP connection is established, the Web browser sends a request command to the Web server. The HTTP protocol encapsulates the request as an HTTP request, including the request line, the request header, the blank line, and the message body.

1.1.3 Return response information

1.1.4 Closing the connection

1.2 Web server defects;

Add a secondary app to generate dynamic pages only by providing static Web content to clients

The secondary is registered on the server side and is searched and run according to the parameters.

1.3 Server-side web programming

The process of building dynamic server-side content –cgi Technology – Microsoft's ASP and ASP. Java-based SERVLET/JSP Technology 1) CGI technology CGI is the Universal Gateway Interface (Common Interface) The biggest advantage is that it can be written in Shell, Perl, C, PHP, Python, etc. but CGI technology is also flawed:

Each request opens a CGI process that consumes server resources severely. Significantly limits the number of concurrent CGI users that a server can support.

2) Java's Resolution Act

Web container;

The Web container is responsible for managing and running the servlet container support for servlets including – Communication support – Lifecycle Management – Multithreading support –jsp support

-Handling security

Servlet

1:servlet is the regular Java code. Some new APIs are used in the code, but the new syntax is not involved.

There are important statements that we are unfamiliar with in the 2:servlet code. The servlet does not belong to J2SE, it belongs to a separate specification.

The 3:servlet extends the standard Class (HttpServlet).

4:servlet does not have a main () method.

Such as:

1 Importjavax.servlet.http.*;2  Public classHelloWorldextendsHttpServlet {3      Public voidDoget (httpservletrequest request,httpservletresponse response)throwsioexception,servletexception{4Response.setcontenttype ("text/html");5PrintWriter out =Response.getwriter ();6Out.println (");7Out.println (");8Out.println ("<title>hello world!</title>");9Out.println (");TenOut.println ("<body>"); OneOut.println ("); AOut.println ("</body>"); -Out.println ("); -     } the}
View Code

Servlet main Tasks

Read explicit and implicit data generation results sent by clients send explicit data (i.e. documents) and implicit data (HTTP response data) to the client servlet specification; The specification defines only the standard functionality that a container must implement the servlet container has many different implementations –tomcat–jboss– Weblogic–websphere–oracle9i asServlet handles requests and responses in conjunction with the Web container

1) The client initiates an HTTP request to the Web server.

2) HTTP requests are accepted by the Web server, and if a static page is requested, the Web server is responsible for processing. If a Java Web Component (servlet or JSP) is requested, it is handed over to the Web container. The Web container can be started in the process of the same process, different processes, or other Web service hosts of the host.

3) The Web container determines the specific servlet class to invoke based on the servlet's configuration file, and passes the request object, the response object, to it.

4) The servlet knows who the client is using through the request object, what the customer's request information is, and some other information. When the servlet finishes processing the request, it puts the information to be returned into the response object and returns it to the client.

5) Once the servlet has finished processing the request, the Web container refreshes the response and returns control to the Web server.

1.4 Composition of Java Web applications

Update in ...

Chapter One how the Java Web works

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.