A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
01-concepts related to web development and common Web Servers
Web development knowledge
Web indicates the meaning of a webpage in English. It is used to indicate resources on an Internet host for external access.
Web resources on the Internet for external access are divided:
Static web resources (such as HTML interfaces): The data on Web pages for browsing remains unchanged.
Dynamic Web Resources: Data on Web pages for browsing is generated by a program. The content displayed when you access a web page at different time points is different.
Static Web Resource Development Technology
Common Dynamic Web Resource Development Technologies
JSP/servlet, ASP, PHP, etc.
In Java, dynamic web resource development technology is called javaweb. The focus of our courses is to teach you how to use Java technology to develop dynamic web resources, that is, dynamic web pages.
To learn about web development, you must first install a web server and then develop corresponding web resources on the Web server for users to access through a browser.
Common web servers
WebLogic is a product of Bea. It is currently the most widely used Web server. It supports J2EE specifications and is constantly improved to meet new development requirements.
Another common web server is IBM's WebSphere, which supports J2EE specifications.
In a small application system or system with special needs, you can use a free web server: tomcat, which supports all JSP and Servlet specifications.
JBoss supports the J2EE specification and works with Tomcat to build a server that supports the J2EE specification.
Official Tomcat site:
Get tomcat installation package
The installation version of The tar.gz file in the Linux operating system
The installation version of the EXE file in Windows
ZIP file compression in Windows
Working port of common protocols on the Internet
02-web server startup Problems
Common Startup Problems
Java_home environment variable
Set java_home environment variables in Windows
If you set the java_home environment variable to the main directory of JDK anywhere before the setclasspath. bat batch file uses the java_home environment variable for the first time, you can start Tomcat using the startup. BAT file.
Port occupation Problems
How to set the environment variable catalina_home
03-tomcaat server directory structure
04- ing between web applications and virtual directories
A Web application is a Web application.
A Web application consists of multiple static and dynamic web resources, such:
HTML, CSS, and JS files
JSP files, Java programs, Jar packages supported
Configuration files ......
These files that make up Web applications usually use a directory organization, which is called the directory where the web application is located.
After a web application is developed, if you want to provide external access, You need to hand over the directory where the web application is located to the Web server for management. This process is called the ing of virtual directories.
<Context Path = "/itcast" docbase = "C: \ News"/> if this configuration is not good, restart the server.
For Tomcat 6, unlike Tomcat 4.X, it is not recommended to place <context> elements directly in the server. XML file. this is because it makes modifing the context configuration more invasive since the main CONF/server. XML file cannot be reloaded without restarting
Context elements may be explicitly defined:
1. In the $ catalina_base/CONF/context. xml file: the context element information will be loaded by all webapps.
2. In the $ catalina_base/CONF/[enginename]/[hostname]/context. xml. default file: the context element information will be loaded by all webapps of that host.
3. in individual files (with ". XML "Extension) in the $ catalina_base/CONF/[enginename]/[hostname]/directory. the name of the file (less. XML extension) will be used as the context path. multi-level context paths may be defined using #, e.g. foo # bar. XML
For a context path of/Foo/bar. The default web application may be defined by using a file called root. xml.
4. only if a context file does not exist for the application in the $ catalina_base/CONF/[enginename]/[hostname]/, in an individual file at/META-INF/context. XML inside the application files. if the web application is packaged as a war then/META-INF/context. XML
Will be copied to $ catalina_base/CONF/[enginename]/[hostname]/and renamed to match the application's context path. once this file exists, it will not be replaced if a new war with a newer/META-INF/context. XML is placed in the host's appbase.
5. Inside a host element in the main CONF/server. xml.
05-roles of the Web application organization structure and web. xml files
Composition Structure of Web Applications
When developing a web application, different types of files have strict storage rules. Otherwise, not only may the web application be inaccessible, but may also cause an error when the web server starts.
Web. xml file
The Web. xml file is the most important configuration file in the Web application and must be placed in the WEB-INF directory. When developing a web application, you can configure the Web Resources in the Web application in the web. xml file. For example:
Configure a web resource as the homepage
Map the servlet program to a URL
Configure listeners for Web Applications
Configure filters for Web Applications
Understanding the functions of Web. xml files:
Use the Web. xml file to configure a web resource as the homepage of a website.
06-configure virtual hosts (build websites)
Configure a VM
Multiple websites can be placed on a Tomcat server. The so-called virtual host configuration means configuring a website on the Tomcat server.
To configure a website on the Web server, use the host element. For example:
<Host name = "Site1" appbase = "C: \ app">
The configured host (website) must be registered on the DNS server or Windows system for external access.
Configure multiple websites.
Default virtual host.
<Host name = "www.sina.com" appbase = "C: \ Sina">
<Context Path = "/mail" docbase = "C: \ Sina \ mail"/>
07-uml Describe Web Resource Access Process
Drawing to demonstrate the Web Resource Access Process
Package Web Application WAR
Jar-CVF news. war news can be automatically decompressed by the server after it is converted into a war package
Configure the reloadable element of the context element to enable tomcat to automatically load the updated web application.
The architecture of Tomcat and the configuration of the private key of the HTTPS Connector
Keytool-genkey-alias tomcat-keyalg RSA
Tomcat server management platform
Web Application Development Prospects B/S C/S
09-software cryptography basics and tomcat HTTPS connector configuration
Create a web application in the webapps directory for external access.
Configure in the server. xml file to map a web application under the C: disk to a virtual directory for external access.
In the Catalina/localhost directory, map a web application under the C: disk to a virtual directory for external access.
Configure a virtual host www.itcast.cn in the server. xml file, and then register www.itcast.cn in the window system.
Create a webapplication named itcastunder the root directory of the virtual terminal, create an index.html page under the application, and map the web application to the default web application. The index.html page is set as the homepage of the Web application.
Change the Web server port to port 80.
Drawing shows how the browser accesses the Web Resources of Web applications under the web host on the Web server.
Common attributes of context elements
10-http protocol overview and hands-on understanding HTTP protocol
What is HTTP?
After the client connects to the Web server, if you want to obtain a Web Resource in the web server, you must comply with a certain communication format. the HTTP protocol is used to define the communication format between the client and the web server.
Use the telnet program to connect to the Web server and use the HTTP protocol to obtain a page to quickly understand the role of the HTTP protocol.
Install the IE browser plug-in httpwatch and check that the IE browser obtains a page through the HTTP protocol.
Cmd.exe --> Telnet localhost 8080 --> Get/hailangxing/1.html HTTP/1.1
HOST: (Press enter directly by default)
HTTP protocol Overview
HTTP is short for Hypertext Transfer Protocol (Hypertext Transfer Protocol). It is an application layer protocol of TCP/IP protocol, used to define the process of data exchange between Web browsers and web servers.
HTTP protocol is the cornerstone of learning Java Web development. Without a deep understanding of HTTP protocol, you cannot master web development and manage and maintain complex web sites.
HTTP versions: HTTP/1.0 and HTTP/1.1
Differences between http1.0 and http1.1
In http1.0, after the client establishes a connection with the Web server, only one web resource can be obtained.
Http1.1 protocol, allows the client to establish a connection with the Web server and then obtain multiple web resources in a connection.
Telnet is used as an example.
A problem that many people cannot understand:
A web page uses the IMG tag to reference three images. When the client accesses the web page on the server, the client accesses the server several times in total, that is, several HTTP requests are sent to the server.
Reduce the number of HTTP requests during design
11-http request lines and Methods
After the client connects to the server, it requests a web resource from the server, which is called an HTTP request sent by the client to the server. A complete HTTP request includes the following content:
One request line, several request headers, and entity content.
GET/book/java.html HTTP/1.1 request line
Accept: */* multiple Message Headers
Referer: http: // localhost/links. asp
Accept-encoding: gzip, deflate
A blank line
Request Line: The request line describes the client's request method, requested resource name, and HTTP Protocol version number.
Request Header: The request header describes the host requested by the client and the environment information of the client.
HTTP request details-Request Line
Get in the request line is called the request method. The request methods include:
Post, get, Head, options, delete, Trace, put
Commonly used: Get and post
If this parameter is not set, all get requests are sent by the browser to the server by default. For example, if the browser directly enters the address access, and the URL access request is a GET request, if you want to change the Request Method to post, you can change the form submission method.
Whether post or get is used to request a web resource from the server, the difference between the two methods is mainly manifested in data transmission:
If the request method is get, you can use? To the server. Multiple Data are separated by "&". For example:
GET/mail/1.html? Name = ABC & Password = xyzhttp/1.1
Get Mode features: the parameters attached to the URL address are limited, and the data capacity cannot exceed 1 K.
If the request method is post, data can be sent to the server in the request object content. The post method features unlimited data volume.
By default, get can be changed to post
<Form action = "/1.html" method = "Post">
<Input type = "text" name = "username"> <input type = "Submit" value = "Submit">
Detailed description of each header field in the 12-http Request Header
HTTP request details-Message Header
Common headers used in HTTP requests
Accept: text/html, image /*
Accept-encoding: gzip, compress
Accept-language: En-US, ZH-CN
HOST: www.it315.org: 80
If-modified-since: Tue, 11 Jul 2000 18:23:51 GMT
User-Agent: Mozilla/4.0 (compatible; msie5.5; Windows NT 5.0)
Data: Tue, 11 Jul 2000 18:23:51 GMT
Accept: indicates the data type supported by the client.
Accept-charset: Used to tell the server that the client uses the Encoding
Accept-encoding: Used to tell the server the data compression format supported by the client.
Accept-language: language environment of the Client
HOST: the client uses this header to tell the server the host name to be accessed.
If-modified-since: the client uses this header to tell the server the cache time of the resource.
Referer: the client uses this header to tell the server from which resource it accesses the server (Anti-leech)
User-Agent: the client uses this header to notify the server of the client's software environment.
COOKIE: the client can use this header to bring data to the server.
Date: Tue, 11 Jul 2000 18:23:51 GMT
13-HTTP response and response status lines
An HTTP response indicates the data that the server sends back to the client. It includes:
One status header, several message headers, and entity content.
HTTP/1.1 200 OK status line
Server: Microsoft-IIS/5.0 Multiple Response Headers
Date: Thu, 13 Jul 2000 05:46:53 GMT
A blank line
<HTML> entity content
Status line: the Status line describes the server's processing results for the request.
Multiple Response Headers: Message Headers are used to describe the basic information of the server and the description of the data. The server uses the description information to notify the client about how to process the data that it will send back later.
Entity content: the data that the server sends back to the client.
Format: HTTP Version Status Code Description <CRLF>
Example: HTTP/1.1 200 OK
The status code is used to indicate the server's request processing result. It is a three-digit decimal number. The response status codes are classified into five categories, as shown below:
Status Code meaning
100 ~ 199 indicates that the request is successfully received, and the client is required to submit the next request to complete the process.
200 ~ 299 indicates that the request is successfully received and the entire processing process has been completed.
300 ~ 399 to complete the request, the customer needs to further refine the request. For example, the requested resource has been moved to a new address, which is usually 302, 307, and 304.
400 ~ 499 client requests have errors, commonly used 404, 403
500 ~ 599 server errors, commonly used 500
200 --> OK
302 --> find someone else
307, 304 --> Get Cache
403 --> resources, but no access permission
404 --> the server does not have this resource
500 --> An error occurred on the server.
14-HTTP response header fields
HTTP requires details-Common Response Headers
Common Response Headers in HTTP requests
Server: Apache Tomcat
Content-Type: text/html; charset = gb2312
Last-modified: Tue, 11 Jul 2000 18:23:51 GMT
Refresh: 1, url = http://www.it315.org
Set-COOKIE: Ss = q0 = 5lb_nq; Path =/search
Date: Tue, 11 Jul 2000 18:23:51 GMT
Location: This header is used with the 302 status code to tell the customer who they are looking.
Server: the server uses this header to tell the Browser Server Type
Content-encoding: the compression format of data through this header.
Content-Length: the server uses this header to tell the browser the length of the data to be sent back.
Content-Type: the server uses this header to tell the browser the type of data to be sent back.
Last-modified: the server uses this header to tell the browser the current resource cache time.
Refresh: the server uses this header to tell the browser how long it will take to refresh
Content-Disposition: the server uses this header to tell the browser to open data as a download.
Transfer-encoding: the server uses this header to notify the browser of the data transfer format.
Etag: cache Header
Expires: the server uses this header to tell the browser how long the sent resource will be cached.-1 or 0 indicates that the resource will not be cached.
The server uses the preceding two headers to control the browser against caching data.
Start building with 50+ products and up to 12 months usage for Elastic Compute Service