2016.5.5 (how Java Web Works)

Source: Internet
Author: User

The process of building dynamic server-side content
CGI Technology
Microsoft ASP and ASP.
Java-based servlet/jsp technology

HTTP is a hyper-text protocol, a stateless protocol


HTTP requests are divided into: 1, Request line 2, request header 3, message body 4, separate request header 5, message body blank line

In version HTTP 1.1, there are eight possible HTTP request methods defined:
1. Get: Used to retrieve resources from the server. Find
2, Post: Used to send data to the server, and require the specified URL processing. (New input)
3. Head: As with the Get method, the server returns only the table row and header, and does not return the requested document.
4. Put: The request server holds the request data as the new content of the specified URL. Modify
5. Delete: The request server deletes the named resource in the URL.
6. Options: Request information about the request method that the server supports.
7. Trace: Request the Web server to feedback the HTTP request and its header
8, connect: A document but currently implemented as a method, reserved for tunnel processing.

The Get method is used to retrieve information to the server, which can provide a finite length of data in the form of a query string. However, the Get method cannot send a large amount of information. Many Web servers
The length of the full URL is limited to 255 characters, and information beyond that length is usually ignored.

The Get method can only be used to execute a query in a Web application, not to perform an update.

The query string is a '? ' Start, followed by a string list of name/value pairs. Multiple name/value pairs are separated by ' & '. For example:/index.html?name=admin&password=admin.

The Post method is used to send data to the server and requires the specified URL to be processed. The Post method can send an unlimited amount of data as part of an HTTP request through a socket connection. Data does not
Appears as part of the URL and is sent only once. Therefore, the Post method is often used to send sensitive information or a lot of information, or to upload files. If an application needs to modify data or
When you add data and send requests over HTTP, you should use the Post method.

Get will let information appear in the browser's address bar so it is unsafe, post does not display so secure.

The response status code is a three-digit number, which is divided into the following groups:
1XX: Information, request received, continue processing.
2XX: Success, Behavior is successfully accepted, understood and adopted.
3XX: Redirect, in order to complete the request, the action must be further performed. Two requests will occur.
4XX: Client error, request contains syntax error or request cannot be implemented.
5XX: Server error, the server cannot implement an apparently invalid request, which is generally a code problem.

A Web server is designed to provide HTTP services to clients, and it can only provide static Web page content to clients.

If you need a dynamic page (a dynamically created page that does not exist before the request is made), you also want to save the data submitted through the form or query string to the server (that is, write to a file or
database), what do I do?
The solution is to run the Web server software (for example: Apache Web server Software) to see that the request is for an auxiliary program, so the Web server starts and runs the program.

A servlet is a Java program that runs on a Web server or application server, primarily for generating dynamic content on the server side. Can be seen as a Java class

The servlet is a regular Java code, with some new APIs in the code, but no new syntax involved.
There are important statements that we are unfamiliar with in the servlet code. Servlets are not part of the Java EE and are separate specifications.
The servlet extends the standard Class (HttpServlet).
Servlet does not have the main () method

The servlet works on the server side primarily to perform the following tasks
1. Read explicit and implicit data sent by the client.
2. Generate results
3. Send explicit data (that is, documents) and implicit data (HTTP response data) to the client.

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


The Web container is responsible for managing and running the servlet

Container support for Servlets includes
Communication support
Life Cycle Management
Multithreading support
JSP support
Handling security


Servlet and Web container processing please
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 you are requesting a Java Web Component (servlet or JSP),
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.

The specification specifies that Java Web applications consist mainly of the following components
Configuration file
static files and JSPs
class files and Packages

About Tomcat
From the Apache Software Foundation Jakarta Project
Meet Servlet and JSP specification requirements
Be able to become a Web server independently
Also a container for servlets and JSPs
Tomcat Directory Structure Introduction

Publish a web App
Make the app catalog into a war package
Deployment
Configuring the Server.xml File
Configure the Web. xml file

CGI programs consume server resources severely, and servlets can eliminate this flaw
The Web container provides an environment for application components that are in the container
A Web application includes configuration files, static files, JSPs, class files, and packages
Tomcat is both an excellent jsp/servlet container and an HTTP server
Server.xml and Web. Xml are the main configuration files for Tomcat
Welcome-file-list indicates which file the server uses when it receives a directory name instead of the URL of the file name

2016.5.5 (how 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.