1. Tomcat Download and install
1.1.
Apache Official website: www.apache.org
Product's homepage: http://jakarta.apache.org
tomcat:http://tomcat.apache.org/
1.2. Version
Installation version: Window (EXE, MSI) Linux (RMP)
Compact version: Window (rar,zip) Linux (tar,tar.gz) is used when learning
1.3. Run and close Tomcat
Start the Software
A) Locate%tomcat%/bin/startup.bat, double-click the file
b) pop-up window, display information (do not close this window)
c) Open the browser and output the following address http://localhost:8080
D) See a cat screen to prove that the software started successfully!
Shutting down the software
A) Find%tomcat%/bin/shutdown.bat and double click on this file!
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/80/1A/wKiom1c3eXPBfntjAAJMTeqy-cg789.png "title=" Tomcat8080.png "alt=" Wkiom1c3expbfntjaajmteqy-cg789.png "/>
2. Tomcat Software Use FAQ
2.1, the problem of Flash back
Cause: The Tomcat software is developed in the Java language. When the Tomcat software starts, it will default to the system's environment variable to find a variable named Java_home. The function of this variable is to find the JVM that Tomcat needs to boot.
The solution is to set the Java_home variable in the environment variable java_home= C:\Program files\java\jdk1.7.0_51 (note Not configured in the bin directory)
2.2. Port-occupied errors
Cause: The port required for Tomcat boot is occupied by other software!
Workaround:
A) Close other software programs and release the required ports
b) Modify the port required for the Tomcat software. Locate and modify the 69th line position of the%tomcat%/conf/server.xml file
<connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443" />
2.3, Catalina environment variable problem
Cause: After the Tomcat software starts, in addition to looking for java_home, it will also look for a variable called catalina_home, the role of this variable is to set the root directory tomcat.
WORKAROUND: We recommend that you do not set the Catalina_home variable. Check if there is, clear off!!!
3. Tomcat directory structure
3.1. Tomcat root directory
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/80/17/wKioL1c3epyzBtRZAABzkjZBbJY435.png "title=" Tomcat _root.png "alt=" Wkiol1c3epyzbtrzaabzkjzbbjy435.png "/>
|-tomcat root directory
|-bin: The command to store Tomcat.
Catalina.bat command:
Startup.bat-Catalina.bat Start
Shutdown.bat-> Catalina.bat stop
|-conf: storing Tomcat configuration information. Where the Server.xml file is the core configuration file.
|-lib: A jar package that supports the operation of the Tomcat software. There are also technical support packages, such as servlet,jsp
|-logs: Log information for the running process
|-temp: Temp Directory
|-webapps:tomcat shared directory. Local resources that need to be shared are placed in this directory. Web App Catalog. (Note that it cannot be shared with a separate file)
The running directory of the |-work:tomcat. The temporary files generated by the JSP runtime are stored here
3.2. Web application directory Structure
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/80/1A/wKiom1c3edmSwm2uAABfzy3TBfw950.png "title=" web_ Root.png "alt=" Wkiom1c3edmswm2uaabfzy3tbfw950.png "/>
Each subfolder under the WebApps folder in the Tomcat root directory is the root of the Web App app
|-webroot:web Application root directory
|-static resources (Html+css+js+image+video)
|-web-inf: fixed notation.
|-classes: (optional) fixed notation. Storing a class bytecode file
|-lib: (optional) fixed notation. Store the jar package file.
|-web.xml
Attention:
1) resources within the Web-inf directory cannot be accessed directly through the browser
2) If you want to access the resources inside the Web-inf, you must configure the resources to a file called Web. Xml.
4. Publish Resources with Tomcat
4.1. The difference between static resources and dynamic resources
Static resources: When a user accesses this resource multiple times, the source code of the resource never changes the resource.
Dynamic resource: When a user accesses this resource multiple times, the source code of the resource may send a change.
4.2. Release static resources
A) Create a MyWeb folder in the WebApps directory of Tomcat
b) Create a mytest.html file that reads as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
c) access through the http://localhost:8080/myweb/myTest.html
4.3. Release dynamic ResourcesServlet: The Java language to write dynamic resource development techniques.
Servlet Features:
1) Common Java class, inherit HttpServlet class, overwrite Doget method
2) The Servlet class can only be handed to the TOMCAT server!!!! (developers can't run themselves!!!) )
The servlet manually writes the steps:
1) Write a servlet program that inherits HttpServlet
Package Com.rk.web;import Java.io.ioexception;import Java.io.printwriter;import java.util.date;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;public class HelloServlet Extends Httpservlet{public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, ioexception{response.setcharacterencoding ("UTF-8"); Response.setcontenttype ("Text/html;charset =utf-8 "); PrintWriter out = Response.getwriter (); Out.write ("This is the first servlet program.) The current time is: "+ new Date ());}}
2) Locate the class bytecode of the HelloServlet classes and copy them to the Web-inf/classes directory in a Tomcat Web application.
3) Configure the servlet in the Web. xml file under the current application.
<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "3.0" 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_3_0.xsd "><!--Configure the internal name of a servlet program--><servlet><!--servlet , you can customize the--><servlet-name>helloservlet</servlet-name><!--servlet class Name: Package name + Simple class name-->< servlet-class>com.rk.web.helloservlet</servlet-class></servlet><servlet-mapping><!-- The internal name of the servlet is consistent with the name above!!! --><servlet-name>helloservlet</servlet-name><!--servlet Access name:/Name--><url-pattern>/ Hello</url-pattern></servlet-mapping></web-app>
4) Start the Tomcat server and run access. Visit Servlet:http://localhost:8080/myweb/hello
Java Knowledge: (3) Tomcat