Tomcat
Tomcat is a core project in the Jakarta Project of the Apache Software Foundation (Apache Software Foundation), developed jointly by Apache, Sun and other companies and individuals. With Sun's involvement and support, the latest servlet and JSP specifications are always reflected in Tomcat, and Tomcat 5 supports the latest servlet 2.4 and JSP 2.0 specifications. Because Tomcat technology advanced, stable performance, and free, so deeply loved by the Java enthusiasts and has been recognized by some software developers, as the current more popular Web application server. The latest version is now 7.0. relevant knowledge of Web applications
Introduction to Web Applications
Application: A software program that allows a user to perform a specific task, mainly divided into desktop applications and Web applications.
Desktop Applications (Desktop application):
Typically refers to an application that employs a client/server architecture (Client/server). C/S mode will be applied and service separation, the system has stability and flexibility C/s mode is equipped with a point-to-point structure model, applicable to the LAN, there is reliable security due to the client to achieve direct connection with the server, there is no intermediate link, so the response speed in C/s mode, The client computer is installed as a client program, and once the software system is upgraded, each client has to install the client program, and system upgrades and maintenance are more complex
Web application (Web application):
Web applications generally refer to applications that use browsers and server structures (Browser/server, or b/s structures). Web applications are made up of Web servers and Web clients. Web server: An application is installed on a Web server that is responsible for receiving client requests for processing and returning results to the customer Web client: Allows the user to request a resource on the server and returns results to the client. The client of a Web application generally refers to a Web browser. Web browser is a software, it knows how to communicate with the server, it also has an important task is to explain the HTML code, the Web page presented to the user
Web application Complete "request-response" process
The advantages of B/s mode:
Easy to maintain: based on B/S model system when you need to upgrade or maintain, just modify the server program. Easy to implement. The performance layer of B/s model can be realized by making HTML of Web page, and the technology of browser and web design is quite mature. And the web system developed with Java technology can be installed on any kind of server system platform, which is often said to have cross-platform. Easy to use, no matter where the customer, as long as the server is running, customers can connect through the network to achieve access to data and operations.
HTTP protocol
Url:uniformresource Locator (Uniform Resource Locator)
For example, http://www.it315.org:80/java/index.html
The main web server software
IIS, Apache, Tomcat installation Tomcat
Tomcat Official site: http://tomcat.apache.org/
From the official online download compression package directly decompression (put in non-Chinese, space in the directory) you can start and stop Tomcat
Double-click the Startup.bat file in the bin directory
Enter http://localhost:8080/to show that the following interface represents a successful installation
Common startup Issues
Java_home Environment variables
Setting Java_home environment Variables in windows
You can start tomcat using the Startup.bat file whenever you set the JAVA_HOME environment variable to the JDK's home directory for the first time before the Setclasspath.bat batch file uses the JAVA_HOME environment variable.
Port occupancy issues: Netstat-na Command and FPort tool (you can see which network port numbers are listening)
Configure the Web site's virtual directory
1. The concept and principle of the mapping of virtual Web directories:
Concept :
If you want a directory content for a computer to be accessed by an outside browser through the HTTP protocol, the steps are as follows:
The first thing to install and start a Web server software on this computer is to map the directory to a Web site directory. This web site directory is often called a virtual directory. Only one virtual directory can have a root directory on a Web site, and other virtual directories must be subdirectories of that directory. The general root directory is represented by the "/" symbol, and subdirectories or resource files under the root directory and the root directory are also split with the "/" symbol.
principles of Attention:
A file system directory can be mapped to multiple virtual Web directories the name can be the form of a multilevel directory structure Tomcat processes the requested URL according to the longest path matching principle
2. To set the directory for your Web site:
(1) Set the virtual root of the Web site
1. Direct access to an HTML document directly in Tomcat\webapps\root
2. You can also set the root directory in the server by using the <Host></Host> tab to set <Context></Context> tags
Absolute path: <contextpath= "" docbase= "E:/myweb" debug= "0"/>
Relative path: <contextpath= "docbase=". debug= "0"/>
Note: A host is a Web site, in the host has a appbase= "WebApps" is the baseline path, and the relative path is the baseline and the benchmark path, that is, the WebApps as a virtual root directory, but generally do not change the root. Remember to add a tail tag when writing a label
(2) Set the virtual subdirectory of the Web site:
First: Add in Server
<context path= "/book" docbase= "e:\test" debug= "0"/>
Note: The debug function is not required, it shows the number of output in the background, 0 means less, 1 means more
The second: HTML in the folder set under WebApps can be automatically treated as a virtual subdirectory
The third is to get the HTML document you want to publish, and you can access the package.
(1) Set the virtual subdirectory for the compressed package the first type
Set the <context path= "/student" docbase= "E:\myweb.war" in the server/>
Access time: http://localhost:8080/student/1-1-2.html
Note: After the compression of the war, compressed files are automatically compressed into webapps under execution.
(2) Set the virtual subdirectory for the compression package the second type
It is possible to copy the package directly to the WebApps, but note that the virtual subdirectory at the time of the visit is the same as the compressed name, all attention to the path.
Note: Pack-and-go command: Jar command is used to package (CD MyWeb)
Jar CVF myweb (compressed filename). War. (All files in the current directory)
3. Default Web page for deployment descriptors and directories
(1) Deployment descriptor
The deployment descriptor is web.xml and exists in two places
One is under the Tomcat/conf/web.xml (because XML is common in this area)
One is to write web_inf/web.xml in every application virtual subdirectory
(2) default page settings:
The first: In the Web.xml in the Conf is the bottom of the <welcome-file-list> this label is the default file
Copy an HTML file named index in the virtual subdirectory and access it directly under the path at run time, just because there are web.xml default files
The second: Build a web.xml,web.xml in the virtual directory under the Web_fin folder
Configuring a virtual host
Host name based virtual host
(1) The process by which a browser accesses a Web resource-------------is the process of entering a path on the address bar:
Format: Http://IP address (or host name): Port number/directory Name/web page file name
Example: http://www.csdn.net/book/java.html
(2) Virtual host and implementation principle:
Purpose: To create multiple Web sites on a single computer and set up different home directories and virtual subdirectories for each Web site, each of which is assigned to a different company or department as a separate Web site. Benefits: Multiple companies or departments of the Web site can share the same computer, and users feel that each company and department have their own independent site. A number of small and medium-sized companies that do not have the strength to set up their own dedicated servers on the Internet can jointly rent a Web server to provide their own web services without affecting each other.
principle:
Each Web site on the Web server must be set up with different identity information the connection and request information from the Web browser contains the identity information for the web site
identification information for the Web site:
IP address, port number, host name
the detailed implementation process
(1) Two sites:
Host Name: site1http://site1:8080/index.html host Name: site2http://site2:8080/index.html
Settings for a virtual host based on host name:
The Connector connector listens for requests from clients Engine engine tags are used to process customer requests, receive connector requests and return to connectors in Engine with host virtual host, a Web site
(2) Add a pair of host tags to the server because there are two sites
(3) http://sitel:8080/test1.html cannot access, because Sitel is the domain name, you must add the domain name before submitting the request, add the domain name according to the following path
C:\WINDOWS\system32\drivers\hosts Add a domain name
127.0.0.1 site1
127.0.0.1 Site2
(4) http://sitel:8080/test1.html can be accessed correctly
a virtual host based on port number
(1) Create two sites:
Web site: 8080
Web site: 8081
Submit Request: Http://localhost:8080/index.html
Submit Request: Http://localhost:8080/index.html
(2) Configure in server: Create multiple <Service> labels after </Service>
<service name= "Tomcat_second" >
<connector port= "8081" protocol= "http/1.1"
20000 "
redirectport=" 8443 "/> <engine name=" Catalina "
defaulthost=" localhost ">