Tomcat installation and configuration of web publishing project
Content Today
1, Web Development basic concepts (understanding)
2, Tomcat installation and configuration (must be)
3, Web publishing project (will be)
4, Http Introduction protocol (understand)
The basic concept of Web Development
1, the software architecture
Commonly used software: QQ, Jingdong, Taobao, kgc
1) C / S architecture
Explanation: The client / server.
Features: need to download and install each update need to download the client and server likely need to be updated
Controls cool, because it calls the graphics system is the underlying API
2) B / S architecture
Explanation: The browser / server architecture. It is Http-based protocol, using a request / response mode.
Features: direct access through a browser, the update does not require user intervention, maintenance on the server side
2, web resources classification
What is a web resource?
On the server , for users to access files, images, CSS, JS, video, audio, etc.
1) Static resources: css, js, html picture video and audio
2) Dynamic resource: If a file is compiled, executed by the container generated files is dynamic resource. Servlet, jsp.
When the user access to resources, dynamic resource and static resources to go the engine is not the same.
3, the concept of a server and a common web server
l What is a server?
Server software and hardware combination. First by the server's hardware, then install the server software, the software can be configured to start up. So that users can access.
l common web server
Concepts: web server that can run the program when the user to deploy to the web server, you can start to access web resources.
1) WebSphere: IBM's server business, free of charge.
2) WebLogic: BEA's server business, charging jsp / servlet
3)IIS ,asp asp.net
4) tomcat: open-source servers, efficient and compact. Tomcat generally now often build clusters in a distributed environment.
4, web dynamic resource structure
Webapp(webroot)
WEB-INF
the web.xml (deployment descriptor file)
lib (file, put the jar file)
jsp(html css js)
The following is the general site creates a special folder to put css, js and imgs similar. Lib put JAR third party, after the copy into, you need to go build path
tomcat installation and configuration
1. Download: https://tomcat.apache.org/download-80.cgi
2. What download?
Description: gz is linux version, zip windows version is, according to the operating system 64 or 32, select the appropriate.
3, installation is decompressed.
1) unzip to the root directory
2) can not be extracted to Chinese folder, without spaces, do not use very special character
4, Configuration
1 ) The software relies jdk , no jdk not run start. Then you must configure jdk environment variable
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_111
CLASSPATH: .;%JAVA_HOME%\lib; %JAVA_HOME%\lib
Configuring path environment variable, preceded% JAVA_HOME% \ bin;
Path environment variable modifications done
D:\Program Files\MySQL\MySQL Server 5.5\bin;
This is the environment variable configuration database
%Java_Home%\bin;
This is the configuration of environment variables jdk
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
%CATALINA_HOME%\bin;
This is the configuration of tomcat environment variables
---------------------------------------------------------------------------------------------------------------------------------
2 ) Configuration tomcat environment
CATALINA_HOME: D:\apache-tomcat-8.0.26
Followed by the% CATALINA_HOME% \ bin;
3) How to determine the successful installation
5, at the command line startup.bat , the following screen appears, the screen does not flash, it means there is no problem. This shows the successful launch
6, the test: Enter the browser HTTP: // localhost: 8080 / ,
7, tomcat directory structure
bin: startup and shutdown tomcat folder.
startup.bat is used to start the server,
shutdown.bat is to stop the server .
Here bat file we called batch files .
A file ending in .sh are startup and shutdown of the file server in the linux environment.
lib: The software package dependent jar
logs: Log Files
temp: temporary folder
webapps: is used to publish your own web application file folder, such as your site can be copied here.
work: put jsp document translation of source files and the compiled byte code file
web publishing project
Learning misunderstanding:
1) We believe that we completed the development of a dynamic site, or to test formally launched, is the time to manually copy the project to webapps?
http: // localhost: 8080 / web01 / xxxxx resources
ANSWER: You can do this, but in the development of debugging efficiency is too low, each time you modify certain code must manually copy, too slow. So we are automatically copied to the webapps following through software. This software copying process is called deployment and publishing . When Nick in this manner? For example, after completion of the project, to the customer site is not generally brought to the scene of the source code (source code does not just give Implementation Engineer), but the compiled file, usually manually copy deployment. The remote copy can also be a way to deploy. (There cloud server, there is an account and password).
2) Posted: handmade copy, and copy tools, such as automatic copying and deployed through eclipse.
Tomcat web project to release a total of three ways:
- WebContent web project directly copied to the tomcat / webapps in.
- Configuring virtual path of tomcat
- Configuring virtual path of tomcat
Method 1: copy items directly to the webapps
Simply copy the web project to webapps can pay attention to it is the content webContext copy this folder.
例如http://localhost:8080/WebContent/NewFile.jsp
http://60.1.1.128:8080/aa/NewFile.jsp
When you need to access someone else's computer to your web page, you need to localhost instead ip address of the machine 60.1.1.128
Get ip address of the way, in the black window type ipconfig
Second way: configure the virtual path of tomcat (not recommended)
Configured in tomcat / conf / server.xml file
In <Host> tag configuration:
<Context path="aaa" docBase="D:/HelloKitty"/>
Three ways: tomcat configuration of the virtual path (recommended)
在tomcat/conf/Catalina/localhost/xxx.xml
配置<Context docBase="D:/HelloKitty"/>
Substituted with the path of the end of the file "D: / HelloKitty"
xxx as the name of the virtual path
Create a xml file
Xml file name is the access path
例如http://localhost:8080/aa/NewFile.jsp
How to get the path?
Task, cmd were used to start the server, and the server is achieved using the eclipse started publishing web project
tomcat eclipse environment configuration and release and deployment of web projects
Note: Do not add to a web server first, because the plug-in will be automatically posted to
Http Protocol Overview
Overview Http agreement
protocol
What is the agreement: both parties need to comply with the rules of
http protocol
What is the http protocol: to require compliance with the rules between the browser and the server. .
Interpretation: is the software agreement, the provisions of the rules of both the browser and the server to be followed. Why do we need to follow the rules? Because it is software, it is a machine to perform, and he will not judge it, just mechanical execution. And binary data in the computer world. Then these data interact and communicate, how the machine knows what it is to execute instructions? Then it must be agreed upon rules. So that it can be.
The role of the http protocol: Specification data transfer between the browser and the server.
http protocol features:
- Based on the request and response model
There must be a request, the responsive
Request and response must be paired
- The default port number is 80
- 3 is a stateless protocol
http protocol version:
1.0 instantly closed in response to each connection.
1.1 now. After each response not hang up, after waiting for a long time, no request will hang up.
Demo http protocol
Packet capture analysis: get way
Requesting section:
GET /ServletDemo/http/demo2.html?name=aaa&age=18 HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://localhost:8080/ServletDemo/http/demo1.html
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Packet capture analysis: post way
Requesting section:
POST /ServletDemo/http/demo2.html HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 15
Referer: http://localhost:8080/ServletDemo/http/demo1.html
Connection: keep-alive
Upgrade-Insecure-Requests: 1
name=bbb&age=38
Response part:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"143-1508222586306"
Last-Modified: Tue, 17 Oct 2017 06:43:06 GMT
Content-Type: text/html
Content-Length: 143
Date: Tue, 17 Oct 2017 06:48:05 GMT
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
hello servlet!!!
</body>
</html>
Detailed http protocol
Request part
Request line
Submission:
There are many ways to submit, commonly used is the get, post, and some put, delete ...
get and post difference:
get submitted parameters will be displayed on the address bar, but do not post
get tend to be limited in size, and post no size limit
get no request body, and there is a post request body
Submit Path:
Protocol version: HTTP / 1.1
Request header
Are displayed in the form of key-value exists, a generally corresponds to a key value, there is something more than one key value
User-Agent: --- represents the type of file browser download, download Chinese documents, IE use URLEncoder encoded, and Firefox will be Base64 encoding
Referer: represents the source page .--- anti-hotlinking
If-Modified-Since: typically used with Last-Modified response header to find the local cache.
Request body
Post submission is submitted to the parameter server
Response part
Response line
Protocol version: HTTP / 1.1
status code :
200 success
302 redirect
Find a local cache 304
404 resources do not exist
500 internal server error
Status Code Description
Response header: value pairs, usually a key corresponding to a value, but also a key value corresponding to a plurality of
Last-Modified: using a look-local cache with the If-Modified-Since header of the request.
A header file download time use: Content-Disposition
Location: Redirect jump path
Refresh: refresh timer / timer jump
problem:
Web, the principle is what the cache?
When the request first time, put the resources and time to the client browser cache folder, the second time when requests for the same resource, the request header will take a If-Modified-Sice (time stamp) to the server What server to find the resources requested last modification time, and this time brought over time to compare, if different, the resources will be re-sent to the browser cache folder, and it will bring a timestamp Last- Modified in the past. If the same, to send a status code 304 (at this time will not be re-sent resource to the browser cache folder), then the browser will automatically find resources to the cache folder and displayed.
Response body:
Displays the contents of the page to the browser
operation:
1 three publishing practice
2, create a web project in eclipse, and configure tomcat, and publish project startup, shutdown.
3, Servlet preview
Learning the bottom line:
1 , will create a web project, you configure the tomcat, will publish a project, start
2 , the servlet creates, configures the deployment descriptor and will pass url to access servlet (relative and absolute paths)
3 , will be obtained from the Request Parameter client browser request object submitted by the servlet (the controller) in the.
It means that the premise will get to submit data from foreground to background from the background. Request object, learn core methods.
4 , will be from background to foreground. It will respond to the data page or the front desk. Reponse objects
5 , the request will be processed in response to distortion or distortion. Request data obtained when the front desk, and if there will be garbled get submitted to be processed. The response data will be garbled by the response process.
6 , to understand the difference between the forwarding and redirection, which in turn selects the appropriate domain object, to store data domain objects. Of course, also obtained from the values stored in the object field.
7 , MVC implementation process
8 , and use JSTL EL expressions (when binding data, the processing cycle, and is determined from the data obtained after binding domain object)
9 , on the basis of three-tier architecture, this is the basis of this foundation.
10 , of the filter used
11 , JSP nine built-in objects and their usage
12 , processes the AJAX, data returns json
13 , a single conditional paging query table
Improve part:
1 , the cookie principles
2 , the session of principle
3 , cross-domain access issues
4 , form submission process repeated
5 , prohibits cookie how treatment?
6 , upload and download files (not with our entrepreneurs to develop framework for handling upload and download)
7 , using a listener scene
8 , users auto-login feature
9 , JSP part of the page ( action, small scripts, expressions of shuffling use)
10 , codes
11 , paging query multiple tables with conditions