Wikipedia:
An HTTP 404 or Not Found error message is one of the HTTP standard response messages (HTTP status codes). This message indicates that the client is browsing the Web page and the server is unable to provide the message, or the server is unable to respond with unknown reasons. This is usually because the corresponding page the user visited has been deleted or moved or never existed. 404 is also one of the most common errors on the Internet. The 404 error message can be confused with “Server not found” or other similar messages.
Simply put, the requested resource does not exist on the server, or if it does, the requested resource is not found on the server through the URL (Uniform resource locator).
What is the URL
The most common occurrence of a 404 is a path error. Let’s look at urls first. URL, or Uniform Resource Locator (URL), is also called a Uniform Resource Locator, location address, or URL. As the name suggests, where are the resources for location services? Where to find the sent Request, and then the server makes a corresponding logical Response.
The standard format of a Uniform resource locator is as follows:
[Protocol type]://[server address]:[port number]/[Resource-level UNIX file path][file name]? [query]# [fragment ID]
Copy the code
The full format of the Uniform Resource Locator is as follows:
Type [agreement] : / / / access credentials information resources need @ [server address] : [port] / [resource hierarchy UNIX file path] [name]? [query]# [fragment ID]
Copy the code
Here’s an example:
http://127.0.0.1:8080/f?kw=%BA%A3%D4%F4%CD%F5&fr=ala0&tpl=5
Copy the code
HTTP is the protocol; 127.0.0.1 is my server address; 8080 is the port number on the server. /f is the path; The/separates directories and subdirectories. ? Kw =%BA%A3%D4%F4%CD% f5&fr = ALA0&tpl =5, yes query. ? Separating the actual URL from the parameters is easy to make mistakes here. Although all data (except numbers) is converted to UTF8 URL encoding, & is used as the delimiter between arguments, = equals (not assignment), and for the first time, there are + for Spaces and # for bookmarks.
Note the format: 1) Generally use Tomcat and nginx server to start the project, you need to check whether the port is correct. 2) Is the protocol name HTTP/HTTPS, domain name or IP address incorrect? 3)/separator to distinguish each directory name in the path with /. In this way, we can search the directory of our project layer by layer according to the URL and analyze whether the possible cause of 404 is path error or the resource does not exist. 3) & represents the parameter, can predict whether its value meets the expectation.
One complete Http request
Understanding the process of our request helps us understand the general flow of the Web. The overall process is as follows: The server responds to the HTTP request. The browser gets the HTML code. The browser parses the HTML code. And request resources in HTML code (such as JS, CSS, images, etc.) -> browser to render the page to the user. So let’s talk a little bit more about what they do. Okay?
1) DNS domain name resolution
What is DNS? The host domain name is converted to an IP address, which is an application-layer protocol and is transmitted using UDP. DNS works as follows: 1. The host queries the local DNS server recursively. Iterative query of local DNS server to root DNS server.
- When a user enters a domain name, the browser checks whether the IP address mapped to the domain name exists in the cache. 2) If no, check the operating system cache (such as Windows hosts) for parsed results. 3) If no match is found, request local domain name server resolution (LDNS). 4) If the LDNS does not match, the root DNS server is directly jumped to request resolution. The root DNS server returns a primary DNS address to the LDNS. 5) The LDNS sends a request to the gTLD returned in the previous step. The gTLD receiving the request searches for and returns the address of the Name Server corresponding to this domain Name. 6) The Name Server finds the target IP address according to the mapping table. Return to LDNS 7) LDNS caches the domain name and the corresponding IP address and returns the resolution result to the user. The user caches the resolution result to the local system cache according to the TTL value. The domain name resolution process is complete.
2) Initiate a TCP three-way handshake to establish a TCP connection
Why does TCP need three handshakes? The explanation given in Xie Xiren’s “Computer Network” is to prevent the failure of the connection request message segment suddenly transmitted to the server, resulting in errors. Three-way handshake: During the first handshake, the client sends a SYN packet (SYN = J) to the server and waits for the server to confirm the connection.
Second handshake: After receiving a SYN packet, the server must acknowledge the client’s SYN (ACK = J +1) and send a SYN packet (ACK = K). In this case, the server enters the SYN_RECV state.
Third handshake: After receiving the SYN+ACK packet from the server, the client sends an ACK packet (ACK = K +1) to the server. After the packet is sent, the client and the server enter the ESTABLISHED state to complete the three-way handshake.
After completing the three-way handshake, the client and server begin transferring data.
How does TCP guarantee reliable transmission
1. Three handshakes. 2. Truncate the data to a reasonable length. Application data is divided into data blocks (numbered by bytes and reasonably fragmented) that TCP considers most suitable for sending. 3. Timeout resends. When TCP sends a segment, it starts a timer and resends 4 if it cannot receive an acknowledgement in time. Confirm reply: the system responds to the received request with confirmation. 5. Checksum: The system discards the packet segment after verifying packet errors. Serial number: Reorders out-of-order data before handing it to the application layer. 7. Discard duplicate data: Duplicate data can be discarded. Flow control. Each side of a TCP connection has a fixed amount of buffer space. The receiving end of TCP allows the other end to send only as much data as the receiving end buffer can accept. This prevents faster hosts from overrunning the buffer for slower hosts. 9. Congestion control. Reduce data transmission when the network is congested.
3) Initiate an HTTP request after establishing a TCP connection
HTTP is a stateless request/response protocol, but this is not enough for today’s business, so there are cookies and sessions, which are used to store state.
An HTTP request packet consists of four parts: request line, header, blank line, and request data. As shown in the figure:
The method name | The intention |
---|---|
POST | Request processing data, generally used to modify, add resources |
GET | Only read data, do not modify, return to the specified page |
DELETE | Deletes the specified resource |
TRACE | It is used mainly for testing or diagnosis and is not commonly used |
CONNECT | Typically used for SSL encrypted server links to proxy servers that can pipe connections. |
Note: Here are the differences between cookies and sessions:
1. Different storage locations. Cookie: stored on the client. Session: stored on the server. The data stored in a Session is secure
2. Different data types are stored. Both are key-value structures, but the types of values are different
Cookie: value can only be a string. Session: value can be an Object
3. Different data size limits. Cookie: size is limited by browser, many are 4K size, session: theoretically limited by current memory,
4. Life cycle control. The cookie’s life cycle dies when the browser closes
(1) The cookie life cycle is cumulative. It starts to be timed from the time of creation. After 30 minutes, the cookie life cycle ends.
(2) The life cycle of the session is interval. From the time of creation, if the session is not accessed in 30 minutes, then the life cycle of the session is destroyed.
4) The server responds to the HTTP request and the browser gets the HTML code
5) The browser parses the HTML code and requests resources in the HTML code (such as JS, CSS, images, etc.)
HTML pages are mainly composed of DOM, CSS, javascript, etc. Other resources such as IMG and IFrame may also be introduced. The browser receives the HTML code, either a complete document or a chunk, and begins parsing. Parsing is done by building the DOM tree, building the render tree from the DOM tree, and finally drawing the render tree to the page by the browser.
6) The browser renders the page to the user
What is rendering? Rendering in computer graphics refers to the process of using software to generate images from a model, that is, converting our Html logic into objects we can see with our naked eyes. Specific class see blog: sylvanassun. Making. IO / 2017/10/03 /…
Some solutions to 404 appear
1) Directories cannot be referenced. Troubleshooting method:
Check the location of the file in Eclipse’s Package Explorer. Due to the meta-inf
The contents of the WEB-INF folder cannot be published, so if you reference a file with either directory, you are definitely not allowed. For example: http://localhost:8080/guestbook/WEB-INF/index.html is wrong
The file location is incorrect
2) Incorrect URL input. Troubleshooting method:
First, check that the IP address and port number of the URL are written correctly.
Second, check the context path is properly Project — — — — — — — — the Properties — — — — — – MyElipse Web — — — — — — — — — –
Web context-root checks that the path name is written correctly.
Finally, check that the file name is written correctly. 3) No Web application is deployed
4) Problems in web.xml in Tomcat server. Troubleshooting method:
If your Web application has multiple JSP pages, you may get a 404 error when you click on the virtual root of your Web application, but you only need to modify the web.xml in the Tomcat server
<init-param>
<param-name>listings</param-name>
<param-value>falseIt should betrue)</param-value>
</init-param>
Copy the code
Error: “Requested resource () is not available.”
/myapp/*.jsp is always inaccessible. You can copy the build. XML file from /ROOT to myapp. Should be OK.
5) Web-INF must have several fixed folders and files under it
±web. XML Configuration file of the Web app ±lib Library file ±classes used by the Web app to store compiled servletsCopy the code
Please note their names. I wrote ‘classes’ as’ class’, so be careful if you don’t waste any more time trying to find their names.
6. If you want to run a servlet (.class) file instead of a.jsp file, configure web.xml(under WEB-INF, of course) and add the following fields:
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/HelloWorldServlet</url-pattern>
</servlet-mapping>
Copy the code
Where “HelloWorldServlet” is changed to the file name you want to run
7) Struts. XML configuration error, may be your Action value or link URL error
Here is my own solution. Many books import six files. In my own case, I add commons-lang3-3.1.jar and Javassist-3.11.ga.jar
Add commons-lang3-3.1.jar file to web-INF /lib.
Download address: download.csdn.net/detail/ahy1…