A Http1.1 javaweb overview
1.2 Overview of the HTTP protocol
1. What is the HTTP protocol
HTTP, Hypertext Transfer Protocol (hypertext Transfer Protocol) is one of the most widely used network protocols on the Internet. All WWW documents must comply with this standard. HTTP was originally designed to provide a way to publish and receive HTML pages
2. The composition of the HTTP protocol
The HTTP protocol consists of HTTP requests and HTTP responses, and when a Web site is entered in a browser, your browser encapsulates your request to a server site, and the server receives a request that organizes the response data into an HTTP response that is returned to the browser. That is, no request, no response.
Here is the illustration:
1.3 HTTP Requests
1) Request Line
Request method: POST, GET
Requested resource:/demoee/form.html
Protocol version: http/1.1
http/1.0, send a request, create a connection, get a Web resource, disconnect the connection.
http/1.1, sends a request, creates a connection, obtains multiple Web resources, and remains connected.
2) Request Header
The request header is some information that the client sends to the server, using a key-value pair to represent the key:value
|
Common Request Headers |
Description (Red master, other understanding) |
|
Referer |
The browser notifies the server where the current request is coming from. If it is direct access, there will be no such header. Commonly used: anti-theft chain |
|
If-modified-since |
The browser notifies the server of the last change time of the local cache. Controls the caching of browser pages with a combination of another response header. |
|
Cookies |
Session-related techniques for storing cookie information cached by the browser. |
|
User-agent |
Browser notification server, client browser and operating system related information |
|
Connection |
Keep the connection state. Keep-alive connection, Close is closed |
|
Host |
The requested server host name |
|
Content-length |
The length of the request body |
|
Content-type |
If it is a POST request, it will have this header, the default value is Application/x-www-form-urlencoded, which indicates that the request body content uses URL encoding |
|
Accept: |
The MIME types that the browser can support. A description of the file type.
MIME format: Large type/small type [; parameter]
For example:
text/html, HTML file
TEXT/CSS,CSS file
Text/javascript,js file
image/*, all picture files |
|
Accept-encoding |
The browser notifies the server that the browser supports the data compression format. such as: gzip compression |
|
Accept-language |
The browser notifies the server that the browser supports the language. Languages of the World (international i18n) |
3) Request body
When the request mode is post, the request realizes the requested parameter, in the following format:
Username=zhangsan&password=123
If the request method is get, then the request parameter will not appear in the request body, will be stitched behind the URL address
Http://localhost:8080...?username=zhangsan&password=123
1.4 HTTP Response
1) Response Line
HTTP protocol
Status code:
The usual status codes are as follows:
200: The request was successful.
302: Request redirection.
304: The request resource has not changed to access the local cache.
404: The request resource does not exist. This is usually a user path write error, or the server resource has been deleted.
500: Server internal error. Usually the program throws an exception.
Status information: status information is changed according to the status code change
2) Response Head
The response is also a key-value pair, and the server returns the information to the client in the form of a key-value pair
|
Common Request Headers |
Describe |
|
Location |
Specifies the path of the response, which needs to be used in conjunction with status Code 302 to complete the jump. |
|
Content-type |
Type of response body (MIME type)
Value: Text/html;charset=utf-8 |
|
Content-disposition |
Parse the body by browser download method
Value: Attachment;filename=xx.zip |
|
Set-cookie |
Session-related technologies. Server writes cookies to browser |
|
Content-encoding |
Compression format used by the server
Value: gzip |
|
Content-length |
Length of response body |
|
Refresh |
Timed refresh, Format: number of seconds; url= path. The URL can be omitted, and the default value is the current page.
Value: 3;url=www.itcast.cn//Three seconds Refresh page to www.itcast.cn |
|
Server |
Refers to the server name, default value: apache-coyote/1.1. Modifications can be made through the Conf/server.xml configuration. <connector port= "8080" ... server= "Itcast"/> |
|
Last-modified |
The server notifies the browser of the last modified time of the file. Used in conjunction with If-modified-since. |
3) Response body
The response body is the page body that the server writes back to the client, the browser loads the body into memory, and then parses the render display page content
Common concepts of web development in two Tomcat2.1
(1) b/s system and C/s system
Brower/server: Browser Server System-----Web site
Client/server: Client Server System-----QQ, Fei Qiu, large game
(2) Web application Server
Server Software for external publishing of Web resources
(3) Web Resources
The resources that exist in the Web application server that are accessible to the outside world are Web resources
For example: HTML, Css, JS, pictures, videos, etc. that exist inside the Web application server
1) Static resources: refers to the Web page for people to browse the data is always the same. For example: HTML, CSS, JS, pictures, multimedia.
2) Dynamic resources: Refers to the Web page for people to browse the data is generated by the program, at different points in time to access the content of the Web page to see the difference. For example: Jsp/servlet, ASP, PHP
Javaweb Domain: Dynamic resources think Java code to dynamically generate HTML
(4) Request and response
(5) URL of the requested address
2.2 Web application server used in Web development
1) weblogic:oracle Company's large toll Web server supports all Java EE specifications
2) WEBSPHERE:IBM Company's large toll Web server supports all Java EE specifications
3) Open source free small and medium Web application server under Tomcat:apache Open Source support servlet and JSP specifications in Java EE
Download and installation of 2.3 tomcat
(1) Download Tomcat
Website address: http://tomcat.apache.org/whichversion.html
(2) Installing Tomcat
Tomcat has installed version and press release (green version)
Installation version in the form of an. exe installation package, double-click Install to our computer, with less
Decompression version, that is, the green version, extracted directly after use, with more
2.4 Tomcat's directory structure
bin: Script directory
Startup script: Startup.bat
Stop script: Shutdown.bat
conf: Configuration file directory (config/configuration)
Core configuration file: Server.xml
User Rights profile: Tomcat-users.xml
All Web project default profiles: XML
Lib: dependent libraries, Tomcat, and jar packages needed in Web projects
logs: Log file.
Localhost_access_log.*.txttomcat Record user access information, Star * represents time.
Example: Localhost_access_log.2016-02-28.txt
temp: Temporary file directory, folder contents can be arbitrarily deleted.
WebApps: The directory where the Web project is published by default.
work: Tomcat handles the working directory of the JSP.
2.5 tomcate Start-up and operation
Double-click Startup.bat under the bin under Tomcat to start Tomcat
Enter http://localhost:8080 in the address bar of the browser and see the following page to prove the successful start
Cause analysis for Tomcat startup unsuccessful:
1) If you do not configure the JAVA_HOME environment variable, when you double-click the "Startup.bat" file to run Tomcat, the Flash is turned off immediately. and must be configured correctly, and Java_home point to the JDK's installation directory
2) port conflict
Java.net.BindException:Address already in Use:jvm_bind <null>:8080
Modify Tomcat/conf/server.xml
2.6 Directory structure for Web applications
Note: The Web-inf directory is protected and cannot be accessed directly by the outside world
2.7 Using Eclipse to bind Tomcat and publish apps
Step 1: Get the server run environment configuration, window/preferences/server/runtimeenvironmen
Step 2: Add a server
Step 3: Select the address of the server on the hard disk, and then all are OK/next/finish
Step 4: Complete success
Step 5: Set the publishing location
Modifying the location of a tomcat publication
Step 6: Project Right-click/run as/run onserver
Javaweb-http and Tomcat