The first chapter briefly Web Development
What is the Web
What is the development JavaWeb
Software Architecture
-
CS configuration software
- C / S architecture : Client / Server client / server. It requires the client computer to install a client program.
- Common applications: QQ, Thunder, 360, etc. Want
- advantage:
- The user experience is good, the effect dazzle
- Control of information security is strong
- The application server running a lighter load data, calculating function part completed in the client.
- Disadvantages:
- Take up hard disk space
- Maintenance problems
- Installation depends on other conditions
- advantage:
-
BS structure of the software
- B / S architecture : Browser / Server browser / server.
- Common applications: online banking system, Taobao, Jingdong 12306, etc.
- advantage:
- Maintenance and upgrades simple and seamless upgrade.
- Without having to install the program, operating system, built-in browser.
- Disadvantages:
- Animation by browser restrictions
- Poor installation control information. For example: the use of online banking requires U Shield, encryption in the browser.
- Data application server running heavier load. Most calculations are performed on the server side, increasing the pressure on the server. Using Ajax can improve the part of the user experience.
- advantage:
WEB communication
WEB using B / S communication mode , for communication through a hypertext transfer protocol (HTTP, Hypertext transport protocol). Written by URL in the browser address bar, and send a request, the server performs corresponding processing according to the request, after the completion of treatment, it will make a response to the browser and server-side resources will be sent to the browser to the server.
WEB server
- server:
- Hardware: in fact, a computer (this computer that requires a lot).
- Software: web server software needs to be installed on this computer.
Common Web server
J2EE Enterprise Java specification development (13). Standards comprising: the servlet, JSP, JDBC, XML, JTA, etc. JavaMail . Specification is the interface in java. J2EE is also known as JavaEE.
WEB server JavaEE specification part or all of the support (realize), that is, to achieve some or all of the WEB server interface.
Common WEB server:
- Tomcat : a free open-source web server Apache organizations. Servlet and JSP specifications to meet the EE.
- WebSphere: IBM large-scale web server developed by a fee. It met all specifications EE development.
- WebLogic: BEA large web server developed by a fee. It met all specifications EE development.
- IIS: applications on the .NET platform.
- Apache: PHP applications on the platform.
Web development resources
Static Resource : refers to a web page for people to browse the data is always the same. For example: HTML, CSS, JS, images, multimedia.
Dynamic Resources : refers to a web page for people to browse the data is generated by the program, visit different points in time to see the content of the web pages vary. For example: JSP / Servlet, ASP, PHP
URL request path
URL (Uniform Resource Locator), uniform resource positioning symbol is a kind of resources on the Internet indicating the position of each file on the Internet has a unique URL.
- Complete the following form
协议://域名:端口号/资源位置?参数=值
http://www.jd.com:8080/index.html?name=123&password=12345
http://124.200.55.1:8080
* 协议,http、https、ftp等
* 域名,域名或IP地址,都可以访问WEB资源
* 端口号,程序必须使用端口号,才可以让另一个计算机访问。http协议的默认端:80
* 资源位置,用于描述WEB资源再服务器上的位置。
* 参数=值,浏览器和服务器交互传递的数据
Chapter HTTP
2.1 Http Profile
What is Http protocol
HTTP protocol: Hypertext Transfer Protocol (HTTP, HyperText Transfer Protocol) is the Internet's most widely used network protocol. Used to define the process of exchanging data between a WEB server and WEB browser.
The role and characteristics Http protocol
The role of the HTTP protocol
- HTTP protocol is the cornerstone of learning JavaWEB development, not in-depth understanding of the HTTP protocol, you can not say mastered WEB development, will not be able to manage and maintain complex WEB site.
Features of the HTTP protocol
- Based on a request / response protocol model.
- Request and response must be paired;
- After the first, request responsive.
- Quick and easy
- Because the transmission request when the transmission request mode and only needs to request path
- HTTP protocol default port: 80
- E.g:
http://www.baidu.com:80
- E.g:
Http protocol version
- HTTP / 1.0, the transmission request, to create a connection, to obtain a web resource , disconnected.
- HTTP / 1.1, the transmission request, to create a connection, a plurality of web resources , disconnected.
Http protocol consisting of
HTTP request protocol, HTTP response protocol.
- HTTP request comprising: a request line , a request header , the request body
- HTTP response comprising: in response to the line , in response to the first response member
Getting Started 2.2 Http protocol
Ready to work
- Create a page, write "form.html", and provide two forms, are set to submit the form to: get and post. The location of the form is set to # submit, submit to represent the current form.
<form action="#" method="get">
用户名:<input type="text" name="username" value="jack"/> <br/>
密码:<input type="text" name="password" value="1234"/> <br/>
<input type="submit" value="get提交"/>
</form>
<form action="#" method="post">
用户名:<input type="text" name="username" value="jack"/> <br/>
密码:<input type="text" name="password" value="1234"/> <br/>
<input type="submit" value="post提交"/>
</form>
3.2.1 Http request Detailed
HTTP请求格式:请求行、请求头、请求体。
The following diagram, we offer two ways request packet capture results: (Chrome browser)
- GET / POST request data capture:
Request line
例如:POST /bj-ee/day13-http-tomcat/web/01-http/form.html HTTP/1.1
请求行必须在HTTP请求格式的第一行。
请求行格式:请求方式 资源路径 协议/版本
请求方式:协议规定7种,常用两种:GET和POST
GET请求:
将请求参数追加在URL后面,不安全。例如:form.html?username=jack&username=1234
URL长度限制GET请求方式的数据大小。
没有请求体
POST请求
请求参数显示请求体处,较安全。
请求数据大小没有显示。
只有表单设置为method=”post”才是post请求.其他的都是get请求。
常见GET请求:地址栏直接访问、<a href=””>、<img src=””> 等
Request header
例如:Host: localhost:8080
请求头从第二行开始,到第一个空行结束。及请求头和请求体之间存在一个空行。
请求头通常以键值对(key:value)方式传递数据。
key为规范规定的固定值
value 为key对应的取值,通常是一个值,可能是一组。
Common request headers | description |
---|---|
Referer | Browser notification server, the current request came from. If direct access, there will not be the first. Commonly used in: security chain |
Cookie | Technology related to the session, the browser cache for storing cookie information. |
User-Agent | Browser inform the server, the client browser and operating system-related information |
Request body
通常情况下,只有post请求方式才会使用到请求体,请求体中都是用户表单提交的数据,每一项数据都使用键值对key=value,多组值使用&相连。
例如;username=jack&password=1234
3.2.2 Http response Comments
HTTP响应格式:响应行、响应头、响应体
Response line
例如:HTTP/1.1 200 OK
格式:协议/版本 状态码 状态码描述
状态码:服务器与浏览器用于确定状态的固定数字号码
200 :请求成功。
302 :请求重定向。
304 :请求资源没有改变,访问本地缓存。
404 :请求资源不存在。通常是用户路径编写错误,也可能是服务器资源已删除。
500 :服务器内部错误。通常程序抛异常。
Response header
指导性信息,服务器指导浏览器,数据格式k:v
响应头也是用的键值对key:value
服务器通过响应头来控制浏览器的行为,不同的头浏览器操作不同。
Common request headers | description |
---|---|
Location | Specifies the path to the response, the status code 302 need to be used in conjunction with, the jump is completed. |
Content-Disposition | Download time use. Parse the text to download a browser |
Set-Cookie | Technology related to the session. Server writes a cookie to the browser |
Refresh | Regularly updated |
Response Body
In response body, that is, the server sends to the browser's text. The body of the page, the browser to display the contents, and empty lines in response to the first division
Chapter III Tomcat server
3.1 What is Tomcat
Tomcat software, is a free, prescribing the source WEB server (receiving the request, send a response)
Apache Software Foundation and Sun jointly developed
Software systems for small, small amount of concurrent access to the scene.
-
Tomcat software, support in JavaEE specifications (Interface)
JavaEE technology platform for a total of 13 specifications
Support for two specifications, Servlet and jsp specifications
3.2 Tomcat installation
Step one: Download a tomcat server software.
https://tomcat.apache.org/download-80.cgi
Step two: extract the downloaded zip file.
将解压后的文件copy到一个没有中文和空格的路径下即可.
例如:D:\develop\apache-tomcat-8.5.28
3.3 Tomcat Launch and Access
- Open Tomcat
- Unzip the directory bin, command startup.bat
- Access Tomcat, access address URL protocol name: // server IP address: port number
- http: // localhost: 8080 may see a cat, Tomcat is used normally
- See page /webapps/ROOT/index.jsp where the Tomcat directory
- Access: how webapps / http / form.html page, write the address http: // localhost: 8080 / http / form.html
- Stop Tomcat
- Unzip the directory bin, command shutdown.bat
3.4 Tomcat FAQ
- JAVA_HOME environment variable, flash back
- Port is occupied, Tomcat default port 8080
- conf / server.xml can modify the port number Tomcat
3.5 Tomcat directory structure
bin:脚本目录
启动脚本:startup.bat
停止脚本:shutdown.bat
conf:配置文件目录 (config /configuration)
核心配置文件:server.xml
用户权限配置文件:tomcat-users.xml
所有web项目默认配置文件:web.xml
lib:依赖库,tomcat和web项目中需要使用的jar包
logs:日志文件.
localhost_access_log.*.txt tomcat记录用户访问信息,星*表示时间。
例如:localhost_access_log.2018-07-07.txt
temp:临时文件目录,文件夹内内容可以任意删除。
webapps:默认情况下发布WEB项目所存放的目录。
work:tomcat处理JSP的工作目录。
3.6 web project directory structure (important)
In JavaEE specification, WEB certain project directory structure, the specific structure is as follows:
项目名称 (webapps 文件夹)
|-----静态资源.HTML,CSS,JS
|-----WEB-INF (不能直接通过浏览器进行访问)
|----web.xml 当前WEB项目的核心配置,Servlet2.5必须有,3.0可省略。
|----lib 当前WEB项目所需要的第三方的jar的存放位置。
|----classes Java源码编译后生成class文件存放的位置。
37 Tomcat publishing project
- Simply copy the project to the up / down tomcat webapps
- Copy the project to tomcat / webapps in
2. Start the server
3. Access Project
http://localhost:8080/aaa/index.html
3.8 IDEA integrated Tomcat
idea configure Tomcat
- Step 1: First open the idea of development tools, then click on the Run menu, select the
Edit Configurations...
menu to open theRun/Debug Configurations
dialog
- Step 2: Add the server, click the plus sign left corner of the dialog box, select Tomcat Server, and then select Local sub-menu,
find the top right corner of Configure ... related to the Tomcat installation directory and press drawing operation
VM options to fill in the content (which is assigned to run memory) :-Xms128m -Xmx256m -XX:PermSize=128m -XX:MaxPermSize=256m
Note:
VM Options filled out: -Xms128m-Xmx256m--XX: PermSize = 128M -XX: MaxPermSize = 256M
the -vmargs description is followed by the VM parameters, so they are actually JVM arguments behind the
-Xms128m JVM initial allocation heap memory
-Xmx256m JVM heap memory allocated to the maximum allowed, DAMA
-XX: PermSize = 128M JVM initial heap memory allocated to the non-
-XX: MaxPermSize = 256M JVM maximum allowable non-allocated heap memory, DAMA
idea to publish web project
IDEA create JavaWeb project (very important)
Publish web project
-
Step 1: configure the application access path
First, open the idea of development tools, then click on the Run menu, select the
Edit Configurations...
menu to open theRun/Debug Configurations
dialog
Step 2 Start Tomcat
Step 3: Visit the project
http: // localhost: 8080 / day01
Problems in webapps and no project we deploy
IDEA start the Tomcat server, temporarily modify Tomcat configuration file that tells Tomcat server, in my project directory out
Creating WEB good project, published directly to the Tomcat webapps:
The IDEA project (important) and after the deployment of Tomcat
WEB resources
WEB application server, any content into them, have become WEB resources including html, css, js, images, videos ...