HTTP protocol and Tomcat server
HTTP protocol1. 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, there is no response without a request.
1. HTTP request
Edit a form.html form page as follows:
Click the Submit button to grab the package as follows
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
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
Tomcat ServerCommon concepts in web development(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
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
Static resources: Data that is accessible to people in a Web page is always the same. For example: HTML, CSS, JS, pictures, multimedia.
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 can be seen differently. For example: Jsp/servlet, ASP, PHP
Javaweb Domain: Dynamic resources think Java code to dynamically generate HTML
Requests and Responses
the requested URL address
Web Application server commonly 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
2. Download and installation of TomcatDownload Tomcat
Website address: http://tomcat.apache.org/whichversion.html
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
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.*.txt Tomcat Records user access information, and 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.
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
directory structure for Web apps
Note: The Web-inf directory is protected and cannot be accessed directly by the outside world
use Eclipse to bind Tomcat and publish your app
Step 1: Get the server run environment configuration, Window/preferences/server/runtime Environmen
Java-web-http protocol and Tomcat server