Knowledge of Tomcat and HTTP protocol

To catch up with the stars 2021-01-21 20:15:38
knowledge tomcat http protocol


Tomcat And http agreement

Resource classification

  • Static resources

    • The resources provided to people in the website are unchangeable , That is to say, different people or at different times , The content you see is the same

    • for example : The news we saw , The user manual of the website , Website function description document and so on

    • As a developer , We wrote HTML、CSS、JavaScript All belong to static resources

    • Be careful : This is about js The file itself is a static resource , however js It can realize the dynamic effect of the interface

  • Dynamic resources

    • The resources provided to people in the website are generated by the program , At different times or different people due to different identities , What you see is different

    • for example : We are 12306 Buy a train ticket on the train , The remaining number of train tickets varies with time , It will gradually decrease , Until the end, there were no tickets left .

    • As a developer , We wrote JSP、Servlet And so on are dynamic resources

System structure

Infrastructure Division
  • C/S structure

  • B/S structure

difference :

  • First of all : The hardware environment is different ,C/S It is usually built on a dedicated network or a small-scale network environment ( LAN ), And you have to install the client . and B/S It's built on a wide area network , Strong adaptability , Usually there is an operating system and a browser .

  • second :C/S Structure ratio B/S The structure is safer , Because the user base is relatively fixed , Better protection of information .

  • Third :B/S Structure maintenance and upgrading is relatively simple , and C/S It is relatively difficult to maintain and upgrade the structure

Pros and :

  • C/S: Is to give full play to the client PC Handling capacity of , A lot of work can be submitted to the server after being processed by the client . The corresponding advantage is that the client response speed is fast .

  • B/S: Low total cost of ownership 、 Convenient maintenance 、 Strong distribution 、 Development of simple , You don't have to install any special software to To operate anywhere , Client zero maintenance , The expansion of the system is very easy , As long as there is a computer that can access the Internet, it can use .

Technology options
  • Model1 Model

  • Model2 Model

  • MVC Model

  • Three layer architecture +MVC Model

Deployment mode Division

Integrated architecture , Vertical split Architecture , Distributed architecture , Flow computing architecture , Microservice architecture .

 

Common server names
Server name explain
weblogic Realized javaEE standard , Heavyweight servers , Also known as javaEE Containers
websphereAS Realized javaEE standard , Heavyweight servers .
JBOSSAS Realized JavaEE standard , Heavyweight servers . Free of charge .
Tomcat Realized jsp/servlet standard , It's a lightweight server , Free open source .

Tomcat

linux install tomcat

1. Put the compressed package in /usr/local/tomcat

2. Get into /usr/local/tomcat Catalog , decompression Tomcat

cd /usr/local/tomcat tar -xvf apache-tomcat-8.5.32.tar.gz

3. Get into /usr/local/tomcat/apache-tomcat-8.5.32/bin

cd /usr/local/tomcat/apache-tomcat-8.5.32/bin

4. start-up tomcat

The way 1: sh startup.sh The way 2: ./startup.sh

5. Modify the firewall rules

The way 1:service iptables stop Turn off firewall ( Don't suggest ); Use which port number to release which one (80,8080,3306...)

The way 2: release 8080 port Modify the configuration file cd /etc/sysconfig vi iptables Copy (yy , p) -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT Change to -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT Restart load firewall or restart firewall service iptables reload perhaps service iptables restart

Tomcat Directory structure details
  • bin: Binary Directory

  • conf: Profile directory

  • lib: What you need to run jar package

  • logs: Log directory

  • temp: Temporary file directory

  • webapps: Default app publishing Directory , It's very important , A folder in this directory represents a java-web application

  • work: working directory

Tomcat Start exception problem
  • The first question is : The start flashed by

    reason : No environment variables configured

    terms of settlement : Configuration JAVA_HOME environment variable ( Make sure you have jdk The path is right , And the path doesn't go to bin, Is to jdk The root path )

    If configured JAVA_HOME Not yet , Just one CTATLINE_HOME , Path is tomcat The root path

  • the second :Address already in use : JVM_Bind

reason : Port occupied

terms of settlement : Find the application occupying the port

Use cmd command :netstat -a -o see pid End the process that occupies the port in Task Manager

  • Third : There are a lot of exceptions from startup , But it works

    reason :Tomcat There are a lot of projects in the middle , Every time you start these projects, they start . And some of these items are abnormal .

    terms of settlement :

     Can find abnormal items , Just take it from the release Directory (webapps) Remove 

    Can't determine the items that report exception , Just decompress a new one Tomcat
  • The fourth one : Other problems

    for example : An exception occurred during startup , But it doesn't start properly . At this point, you need to unzip a new Tomcat start-up , To make sure it's a system problem , still Tomcat The problem of

    therefore , At this point, we need specific questions , make a concrete analysis , And then we can solve it symptomatically

Tomcat The code problem

Problem description : start-up tomcat after , Console ( Command line ) Garbled

Problem solving :

  • open tomcat Under the table of contents conf/logging.properties file

  • Revised as follows :( take UTF-8 Change it to gbk, because cmd The character set of the command line window is gbk, So we need to unify )

Restart tomcat

HTTP agreement

What is? Http agreement ?

HTTP The full name is :Hyper Text Transfer Protocol, Meaning for Hypertext transfer protocol . It refers to the Q & a rules that must be followed in the interaction between the server and the client . Describe the rule : Question and answer mechanism 、 handshake mechanisms .

It regulates the type and format of request and response content .

HTTP Agreement is made W3C Organization, management and maintenance .

HTTP Explanation of the agreement

HTTP The concept of protocol is a question and answer rule for client browsers and servers , Then there must be questions and answers , And you have to ask before you answer . But we use <script>,<link> and <img> label , There is no manual request , But you can still get the data from the server , The reason is that : In the browser <script>,<link>,<img> The request is made automatically when the tag is added .

Common analysis of message header

The header name is capitalized , Multiple words, each with a capital letter . Use more than one word - Separate Use... Between name and value Colons and spaces Separate Use... Between multiple values Comma with space Separate Between two heads enter Separate

Ask for detailed explanation

Request line :

Content explain
GET How to request .( also POST)
/myapp/2.html Requested resources .
HTTP/1.1 Protocol used , And the version of the agreement .

Request header :

Content explain
Accept Inform server , What the client browser supports MIME type .
Accept-Encoding Inform server , Compression encoding formats supported by client browsers . The most common is gzip Compress .
Accept-Language Inform server , Languages supported by the client browser . It's usually zh_CN or en_US etc. .
Referer Inform server , The source of the current request . Only when the current request has a source , That's the message header . There is no source for the input from the address bar . effect :1 Put an advertisement 2 Anti theft chain
Content-Type Inform server , Request the text of MIME type .
Content-Length Inform server , The length of the request body .
User-Agent Browser related information
Connection: Keep-Alive The state of the connection : Keep connected
If-Modified-Since Inform server , Last modification time of client browser cache file .
Cookie(****) Session management related , Very important .

Request body :

First of all : Only post Request mode , The body of the request .get The text of the method is in the address bar . second : The input fields of the form are name Attribute will be submitted . Regardless of get and post Request method of . Third : Form enctype Attribute values determine the form of the request body . The meaning of the overview is : Request the text of MIME The encoding type .

ENCTYPE Value The form of the request body Example
application/x-www-form-urlencoded key=value&key=value username=test&password=1234
multipart/form-data At this point, it becomes multi part form data . Most parts are separated by separators . -----------------------------7df23a16c0210 Content-Disposition: form-data; name="username" test -----------------------------7df23a16c0210 Content-Disposition: form-data; name="password" 1234 -----------------------------7df23a16c0210 Content-Disposition: form-data; name="headfile"; filename="C:\Users\zhy\Desktop\ Request part .jpg" Content-Type: image/pjpeg -----------------------------7df23a16c0210
Response details

Response line :HTTP/1.1 200 OK

Content explain
HTTP/1.1 Use the version of the protocol .
200 Response status code
OK Status code description

Common status codes :

200 all OK>

302/307 request redirections ( Client behavior , Two requests , The address bar changes )

304 The request resource has not changed , Use the cache

404 Requested resource not found , This error occurred , It's usually the wrong path

500 Server error , Grammatical or logical errors , for example : Null pointer

Response head :

The message header explain
Location The address to request redirection , Often with 302,307 In combination with .
Server Server related information .
Content-Type Tell the customer the browser , In response to the text MIME type .
Content-Length Tell the customer the browser , Length of response body .
Content-Encoding Tell the customer the browser , The compression encoding format used in the response text . frequently-used gzip Compress .
Content-Language Tell the customer the browser , The language that responds to the text .zh_CN or en_US wait .
Content-Disposition Tell the customer the browser , Open the response body as a download .
Refresh Refresh regularly
Last-Modified The last modification time of the server resource .
Set-Cookie(***) Session management related , Very important
Expires:-1 The cache time of the server resource to the client browser
Catch-Control: no-catch Do not cache ,// in the light of http agreement 1.1 edition
Pragma:no-catch Do not cache ,// in the light of http agreement 1.0 edition

Response Content

It's the same as what we see when we right-click on the browser to view the source file .

 

版权声明
本文为[To catch up with the stars]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210121201500986i.html

  1. Ali Java back end online pen test questions and answers
  2. Linux 所有命令无法使用的解决方法
  3. Java工程师【2020升级版】
  4. Spring Cloud分布式微服务实战,养成应对复杂业务的综合技术能力
  5. Java全栈工程师
  6. Spring Cloud分布式微服务实战,养成应对复杂业务的综合技术能力
  7. 基于Docker搭建Hadoop集群
  8. Java架构师-十项全能:打造高度深度广度兼备的全面技术人才
  9. 前端学习(2734):重读vue电商网站44之使用 echarts
  10. Java Architect decathlon: building comprehensive technical talents with high depth and breadth
  11. Front end learning (2734): Reread the use of echards in Vue e e-commerce website 44
  12. 函数式编程
  13. Functional programming
  14. Common commands of docker
  15. Linux调优相关命令汇总
  16. Summary of Linux tuning related commands
  17. 为什么说HashMap是无序的
  18. Why is HashMap unordered
  19. Using Prometheus and grafana to build a monitoring system for hivemq
  20. kafka和zookeeper在k8s集群踩的一些坑
  21. MySQL中整各种int类型的范围和存储大小
  22. Spring Boot常用starter
  23. Range and storage size of various int types in MySQL
  24. Spring boot commonly used starter
  25. Dubbo source code analysis - loadbalance of cluster fault tolerance
  26. Dubbo source code analysis - service call process
  27. Dubbo source code analysis
  28. Dubbo source code analysis - router of cluster fault tolerance
  29. Mybatis source code analysis - built in data source
  30. Mybatis source code analysis - plug in mechanism
  31. [open source] creating docker image does not depend on Linux and docker environment
  32. Specifying default values when objects are deconstructed in JavaScript
  33. The inconsistent results of regular matching in JavaScript
  34. Spring boot 2. X basic tutorial: using redis's publish subscribe function
  35. Spring boot 2. X Basics: how to extend requests and responses in XML format
  36. Several ways to realize general auth authentication in spring boot
  37. Basic tutorial of spring boot 2. X: changes of data script initialization after version 2.5
  38. You must know the high-level Java enumeration features!
  39. Spring boot 2. X basic tutorial: using mongodb
  40. Basic course of spring cloud Alibaba: perfect integration with Dubbo
  41. What about complex mathematical operations such as sin, log and tan in Java?
  42. Initial experience of serverless: rapid development and deployment of a Hello World (Java version)
  43. Spring boot core technology guide for building multi tenant SaaS platform
  44. Self built API gateway architecture design
  45. Let me ask you a question: will this transaction be rolled back?
  46. Interview questions of design pattern
  47. Spring boot 2. X basic tutorial: using @ scheduled to achieve timing tasks
  48. Oracle common background table query