1. Javaweb ConceptJava Web, is the use of Java technology to solve the relevant web technology in the field of the general name. The web includes two parts: Web server and Web client.
Java applets were used in the earliest web client applications, but the technology was eliminated long ago. Java is very rich in server-side applications,
such as servlet,jsp and third party frameworks, and so on. Java technology has injected a powerful impetus into the development of the web domain
Simply put, the Java language is used to implement the content of the program that the browser can access. Called the Java Web.
Javaweb development is based on request and response:
Request: the browser (client) sends information to the server
Response: Server to (client) browser loopback information
The request and response appear to be in pairs.
2, Web resource classification: the so-called web resources are placed on the Internet for external access to the file or program, and according to their rendering effect and principle of different, they are divided into static resources and dynamic resources.
Static Web Resources : Fixed unchanging data files (static Web page HTML, CSS files, text, audio, video)
Static web technology : Html+css+javascript
Dynamic Web Resources : A section of a service program that runs after the generated data file
Dynamic Web Technology : servlet,jsp,php,. NET, Ruby, Python, etc.
3. Common Web servers
Introduction to Web server: Tomcat: A Web server provided by the Apache organization that provides support for JSPs and servlet. It is a lightweight javaweb container (server) and is currently the most widely used Javaweb server (free).
Jboss: An open source, Java-compliant EJB server that complies with the Java EE specification, and supports all Java EE specifications (free of charge).
GlassFish: A javaweb server, developed by Oracle, is a robust commercial server that achieves product-level quality (with few applications and charges).
Resin: Is the Caucho company's products, is a very popular application server, the servlet and JSP provides a good support, performance is also relatively good, Resin its own use of Java language development (fees, applications more).
WebLogic: Oracle Company Products, is currently the most widely used Web server, support Java EE specifications, and constantly improve to adapt to new development requirements, suitable for large-scale projects (fees, not much, suitable for large companies).
3.1. Tomcat Server
Open source Small Web server, completely free, mainly for small and medium Web projects, only support servlet and JSP, such as a small number of Java EE specifications (is the Javaweb programming interface)
3.2. The relationship between the Tomcat server and the servlet version Servlet:sun The technology provided by the company for developing dynamic Web resources.
JSP: (Java Server page), Java provides a technology for developing web pages.
Tomcat Software: Java-developed. The Java software needs JDK when it is running.
Backward TOMCAT7 also supports the servlet3.0/jsp2.2 specification, which can support javaee6.0 current enterprise-common versions 6.*/7.*/8.*
3.3, Tomcat download and installation instructions to the http://tomcat.apache.org download
1) Tomcat home
2) Tomcat download
3) After the download of the package
4) Installation: Decompression
5 Introduction of Tomcat installation directory:
Bin: The file can be executed.
Conf:tomcat Server's configuration file
Lib:tomcat jar packages that need to be dependent upon startup
Logs:tomcat log files after work
WebApps: Is the directory of Tomcat project.
After the work:jsp file is translated, it is saved in the current directory, where the session object is saved after being serialized
3.4, Tomcat server startup (* * key)
Precautions:
1, Java_home: Environment variables. and configure to the JDK directory, the complete process is as follows:
Open the console (CMD command opens the window). Input java-version Test
2, start the Tomcat directory. The Tomcat directory/bin/startup.bat (window startup file) finds Startup.bat double-click Run. There will be a black window, the Black window does not close. (if closed, it's the equivalent of stopping Tomcat.) )
3, in the browser address bar input: http://localhost:8080 or http://127.0.0.1:8080localhost, if you see the following page, to prove the success of the launch
3.5, configure Tomcat Port (* * * focus)
The Tomcat default port is 8080 (Access port)
The default port for HTTP is 80, and if accessed, the input http://www.baidu.com is equivalent to http://www.baidu.com:80. When the project is actually on the line, usually adopt 80, modify the method as follows:
1) Find the Tomcat directory/conf/server.xml
2 Modify port value to change port value to
3) then enter the HTTP://127.0.0.1:80 or http://127.0.0.1 access test in the browser
Access successful ...
3.6, Catalina run start Tomcat Tomcat starts, and one way to start it is to switch your current directory to your Tomcat directory \ Bin directory on the command line, which is my location.
Then execute Catalina Run this command to start Tomcat. What is the advantage of this order? When Tomcat fails to start, there is a flash of the situation,
When we start Tomcat using the Catalina Run command, we can clearly see why Tomcat failed, even if there were errors. Not a flash.
3.7, Tomcat shutdown there are three ways.
First: Ctrl + C to close Tomcat server
Second: Click on the top right corner of the Tomcat window to close the button (violence stops the server)
Third: Locate the Tomcat directory/bin/shutdown.bat file, double-click Execute to turn off Tomcat.
4, the common layout of the project to Tomcat in two ways
Put the html,servlet of our own writing to this information and deploy it to Tomcat's way.
4.1, the first method: in the Tomcat directory/conf/server.xml configuration---Understand the Conf/server.xml file in the host element configuration, for example:
Write the following in the host tag
<context path= "/atguigu" docbase= "D:\atguigu"/>
<context path= "directory where the browser is to be accessed---virtual directory" docbase= "the disk directory where the Web site resides"/>
After you have configured it, restart the server.
Disadvantage (after Tomcat7.0): If configuration error: Tomcat will fail to start. (If other sites are stored in Tomcat), other sites will also be shut down.
4.2, the second way: the Site Directory copy to the Tomcat/webapps directory (commonly used, must be mastered) has a Web site (a folder), the folder copied to Tomcat's WebApps directory.
The name of the folder is the Access directory for the site or project. Equivalent to configuring <context path= ""
4.3, the Site Directory compressed into a war package deployed to Tomcat War package: is a compressed file Zip format compressed files. Only the extension is not. zip But. War
Zip Our project into war, copy the war file to the Tomcat/webapps directory
Step 1, the contents of the folder compressed into a zip format, click on a folder to deploy, select all and then compress
Step 2, modify the file suffix named. War
Step 3: Copy the war file to the WebApps directory. Tomcat will unpack the war files on its own.
4.4. Access to the/root project under the WebApps directory when we enter the HTTP://IP address directly in the browser: port number so the default access is the Tomcat directory/webapps/root directory
If there is a root project under the WebApps. Then, when you visit, you can omit the name of the project directly/indicate that the root directory is found
5, the integration of Tomcat and Eclipse development tools (* * Common must master)
5.1. Open Eclipse's Server view window
in the first case, open the Servers window directly in the second case, the Search Servers window opens
Figure I, open the total Eclipse View two: Input Server filter out Server window Option Servers Server window opened successfully, as shown in the following figure:
5.2. Create Tomcat server
1 in the Servers window, click the text prompt to create the server to connect. The following figure: 2 Creating a new Tomcat server instance
3 Click the Browse button to open the Directory Selection window. Select Tomcat Extract Directory
4 Select the Tomcat directory and click the OK button
5 After the selection of the Tomcat directory, click the "Next" button to continue operation
6) Click "Finish" button to finish the operation
7) Tomcat Server created successfully ...
5.3. Start the Tomcat server in Eclipse 1 Debug mode start Tomcat Server
Prompt is currently starting in debug mode ...
Tomcat starts a successful console prompt ...
2 run mode start Tomcat server
Run mode startup display
Tomcat starts a successful console prompt ...
5.4. Stop Tomcat server in Eclipse violence stops tomcat (the equivalent of a computer being unplugged). There is no preparatory operation to perform the shutdown. )
Normal Stop Tomcat (equivalent to clicking on the Shutdown button in the operating system, performing shutdown save operation, then shutdown)
5.5. Configure the Web engineering path for Tomcat in Eclipse 1 Open Servers window, double-click Tomcat v6.0 Server servers to open Tomcat configuration window
Here are three different options for Eclipse to release the project.
2 Tomcat Location-Options Introduction Description:
2.1. The User workspance metadata (does not modify TOMCAT installation) will eclipse the workspace directory in the eclipse's working interval directory \.metadata\.plugins\ Org.eclipse.wst.server.core\tmp0\ has a copy of Tomcat. All of the Web projects in the city are going to be in Eclipse's working space directory \.metadata\.plugins\ In the Org.eclipse.wst.server.core\tmp0\wtpwebapps directory
2.2. User Tomcat installation (takes control of Tomcat installation) make changes in the original Tomcat directory all the Web works for the project will be posted to the Tomcat directory In the Wtpwebapps directory
2.3. User Custom location (does not modify Tomcat installtion) customizing a directory to Web engineering
For example, the operation is as follows:
One: Select a custom cloth directory
Second: Select your custom directory, then click OK. Then some of Tomcat's catalogs will be copied over. The project is also under the directory of the Wtpwebapps directory Three: Select the project you want to work, right-click the menu Run as--->>> run on Server to the newly customized directory. Four: Select which server you want to use for your current Web project. If you check the Always use this server time running this project indicates that the next time the server is run, the server selected when the tick is run is used by default.
Five: Wait for Tomcat to start, Web engineering after the success of the summer. View
VI: Enter the http://127.0.0.1:8080/day06/index.html Test view in the browser
6 Introduction to HTTP protocol
6.1. HTTP protocol 1.HTTP (Hypertext Transport Protocol), Hypertext Transfer Protocol. This protocol provides a detailed set of rules for communication between browsers and the World Wide Web server.
2. The content that is transmitted when the client communicates with the server is what we call the message.
3.HTTP is a communication rule that stipulates the message format that the client sends to the server, and also the message format that the server sends to the client. The real thing we have to learn is these two kinds of messages. Client sent to the server called "request Message", the server sent to the client called "Response message."
Vernacular said, what is the agreement. is the mutual agreement between the two sides of the rules; for example: Rental agreement: Rental agreement is the tenant and the landlord of the mutual agreement between the rental rules
6.2. HTTP protocol format requested by the requested protocol format :
Request Line
Request headers
Blank Line
Request Body
Get Request protocol format (GET request has no request body)
Post Request Protocol format
6.3. Description of common request headers
get/hello/index.jsp Http/1.1:get request, request the server resource path hello/index.jsp, the protocol is HTTP version 1.1;
Host:localhost: The requested host name is localhost;
user-agent:mozilla/4.0 (compatible; MSIE 8.0 ... : Information related to the browser and the OS. Some websites will display the user's system version and browser version information, all by obtaining user-agent header information;
Accept: */*: Tell the server, the current client can receive the type of data, */*, it means that anything can receive;
ACCEPT-LANGUAGE:ZH-CN: The language supported by the current client, which can find language-related information in the browser's tool options;
Accept-encoding:gzip, deflate: supported compression format. When the data is passed on the network, the server may compress the data and send it again.
Connection:keep-alive: The client supports the link way, maintains the link for a period of time, the default is 3000ms;
6.4, get requests and post requests are respectively.
GET request
1, enter the browser address bar input address, press ENTER directly
2), click <a> hyperlink
3), GET request form submission
4), Script src= "", the introduction of external documents
5, img src= "Path", the introduction of pictures
6), the introduction of external CSS ...
POST request
1 only when the form is submitted method=post, submitting the form is to send a POST request
6.5, the response of the protocol format response to the HTTP protocol format
Respond to the first line
Response header Information
Blank Line
Response body
6.6, the Common response code Response code is very important to the browser, it tells the browser the results of the response;
200: The request is successful, the browser will display the response body content (usually HTML) in the browser;
404: The requested resource is not found, indicating that the client has requested a non-existent resource;
500: The request resource was found, but there was an error inside the server;
302: Request redirection, when the response code is 302, the server requires the browser to resend a request, the server sends a response header location, which specifies the URL address of the new request;
7, servlet (emphasis * * *)
7.1. The servlet introduction servlet is a small Java program that runs on a WEB server. Servlet typically receives and responds to requests from WEB clients via HTTP (Hypertext Transfer Protocol).
To implement this interface, you can write a generic servlet that extends the javax.servlet.GenericServlet, or write an HTTP servlet that extends the javax.servlet.http.HttpServlet.
This interface defines the method that initializes the servlet, the method that provides the service for the request, and the method of removing the servlet from the server. These methods are called life cycle methods, which are called in the following order:
1. Construct a servlet and initialize it using the Init method.
2. Handle all calls to the service method from the client.
3. Remove the servlet from the service and destroy it using the Destroy method, and finally garbage collection and terminate it. Servlet:
1, accept the message sent by the browser.
2, return the message to the browser. browsers recognize HTML. can dynamically output HTML
7.2. Quick start of servlet
7.2.1, how to create a Dynamic Web project 1 Create a Dynamic Web project first