Full solution of tomcat server, tomcat server
① B/S, C/S comparison (1) C/S structure is the Client/Server (Client/Server), such as QQ; you need to write the Server-side program and Client program, for example, we installed the QQ client program. Disadvantages: when updating the software, we need to update both the client and the server at the same time, which is troublesome. Advantages: better security. (2) B/S structure: Browser/Server; advantage: you only need to write the Server-side program; disadvantage: poor security. ② WEB Resources (1) Web resources Introduction html: static resources; JSP/Servlet: Dynamic resources. Of course, in addition to Java Web programs, there are other Web programs, such as ASP and PHP. (2) differences between static resources and static resources: If a webpage requested by the client is a static webpage, the server will directly send the content of the static webpage to the client. If the client requests a dynamic webpage, the server first needs to convert the dynamic web page into a static Web page, and then return the transformed static Web page to the client. (3) Access Web resources open the browser and enter the URL ③ the Web server is used to receive client requests and respond to the client. For Java Web programs, JSP/Servlet containers are also required. The basic function of JSP/Servlet containers is to convert dynamic resources into static resources. Of course, JSP/Servlet containers not only provide these functions, we need to use Web servers and JSP/Servlet containers, which are usually integrated. JavaWeb server: Tomcat (Apache): currently the most widely used JavaWeb server; 4 Tomcat download Tomcat can download to the http://tomcat.apache.org. Tomcat is divided into the installation version and decompressed version: the installation version: Only one Tomcat can be installed on a computer; the decompressed version: no installation is required, and you can decompress the package, so we chose to decompress the version (1) Tomcat directory structure: extract the decompressed version of Tomcat to a path without Chinese characters and spaces. It is recommended that the path be too deep, because we often need to go to the Tomcat installation directory. For example: F: \ apache-tomcat-7.0.42 (2) Start and close Tomcat before starting Tomcat, We must configure the environment variable JAVA_HOME: JAVA_HOME first, JDK is required for Tomcat startup. CATALANA_HOME: If the installation version is used, you need to configure this variable to specify the installation path of Tomcat, for example, F: \ apache-tomcat-7.0.42. Start: Enter the % CATALANA_HOME % \ bin directory and find startup. bat, double-click it. Close: Enter the % CATALANA_HOME % \ bin directory and find shutdown. bat, double-click it; startup. bat will call catalina. bat, While catalina. bat will call setclasspath. bat, setclasspath. bat uses the JAVA_HOME environment variable, so we must correctly configure JAVA_HOME before starting Tomcat. Startup question: Click startup. after bat, the window disappears with a flash: Check whether the JAVA_HOME environment variable is correctly configured. (3) Go to the Tomcat homepage and access: http: // localhost: 8080 (configured port number). Open % CATALANA_HOME % \ conf \ server. the default http port number of the xml file is 80, which means port 80 is used when no port number is provided in the URL. You can also change it to another port number. After you change the port number to 80, you only need to enter http: // localhost in the browser to access the Tomcat homepage. ⑤ Tomcat directory structure (1) bin: This directory stores binary executable files. If it is an installed version, there will be two exe files in this directory: tomcat6.exe、tomcat6w.exe, the former is to start Tomcat in the console, and the latter is to start Tomcat in the ugi window. If it is to decompress the version, there will be startup. bat and shutdown. bat file, startup. bat is used to start Tomcat, but you need to configure the JAVA_HOME environment variable to start, shutdawn. bat is used to stop Tomcat; (2) conf: This is a very important Directory, which has four most important files: Login server. xml: configure the overall server information. For example, modify the port number and add a virtual host. This file is described in detail below; ⒉ tomcatusers. xml: stores tomcat user files. the user name and password of tomcat and user role information are saved here. You can add a tomcat user according to the comments in the file, and then enter the Tomcat Manager page on the Tomcat homepage. xml: deployment descriptor file. Many MIME types are registered in this file, that is, the document type. These MIME types are document types between the client and the server. If a user requests an html webpage, the server will also tell the client browser that the response document is of the text/html type, this is a MIME type. The client browser knows how to handle the MIME type. Of course, this html file is displayed in the browser. However, if the server responds to an exe file, the browser cannot display it, but the download window should pop up. MIME is used to describe the content type of the document! Encryption context. xml: Unified configuration of all applications. We usually do not configure it. (3) lib: Tomcat class library, which contains a lot of jar files. If you need to add the jar file that Tomcat depends on, you can put it in this directory. Of course, you can also put the jar file that the application depends on in this directory, all jar projects in this directory can be shared, but when your application is put under another Tomcat, you cannot share the Jar package in this directory, therefore, we recommend that you only store the Jar package required by Tomcat in this directory. (4) logs: This directory contains all log files and records Tomcat startup and shutdown information. If there is an error when Tomcat is started, the exception is recorded in the log file. Temporary temp: stores temporary Tomcat files. You can delete the files in this directory after stopping Tomcat! ⑹ Webapps: directory for storing web projects. Each folder is a project. If a directory already exists, it is built with tomcat. Project. ROOT is a special project. If the project directory is not provided in the address bar, it corresponds to the ROOT project. Http: // localhost: 8080/examples to enter the sample project. Examples is the project name, that is, the folder name. Running work: the files generated during the running, and the final running files are all here. Generated by using a project in webapps! You can delete the contents in this directory, and the work directory will be generated again when you run it again. When a client user accesses a JSP file, Tomcat will generate a Java file through JSP, and then compile the Java file to generate a class file. The generated java and class files will be stored in this directory. LICENSE: LICENSE. NOTICE: description file. ⑥ Web application (important) Static Website: create a directory under the webapps directory (the name must not contain Chinese characters or spaces), which is called the project directory; create an html file under the project directory; Dynamic Website: Create a project directory under the webpass directory; create the following content under the project directory: WEB-INF directory; Create web under the WEB-INF directory. xml file creation static or dynamic page (1) create a static application create a hello directory under webapps; Create index.html under webapps \ hello \; start tomcat; open a browser to access http: // localhost: 8080/hello/index.html (2) create dynamic app create hello1 directory under webapps; Create WEB-INF directory under webapps \ hello1 \; Create web under webapps \ hello1 \ WEB-INF. xml; web. xml configuration <? Xml version = "1.0" encoding = "UTF-8"?> <Web-app version = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> </web-app> Create index.html under webapps \ hello1. Open a browser and access http: // localhost: 8080/hello/index.html (3). Configure the external application. Our project is placed under webapps. Now, I want tomcat to find it! You can also put the application out of Tomcat, which is an external application. For example, we cut the hello application written above from the webapps directory to drive C:/hello. Now hello, this Web application is no longer in Tomcat. In this case, we need to configure the location of the External Application in tomcat. There are two Configuration Methods: Begin conf/server. xml: Open server. in the xml file, locate the <Host> element and add the <Context> element. The Code is as follows: