Instructions for the Web server Tomcat (role and protocol issues in Web Access and program structure issues for Javaweb projects)

Source: Internet
Author: User
Tags tomcat server apache tomcat

1. The concept of C/s architecture and B/s architecture:

A, c/s architecture:

-C/s,client/server, client/server, client needs to install dedicated client software. The client is a software specifically developed for a specific business.

-Because the client is a dedicated software, the client program generally has the ability to process the specific business. This reduces the processing pressure on the service side, making the service-side operation faster and responding to the client faster.

-It is also because the client is specialized software that needs to be specially installed, so the system that causes the C/S architecture also has the fatal problem: The version upgrade cost is unusually high. Either because the client software itself is upgraded, or because the server upgrade causes the client to upgrade, for whatever reason the client needs to upgrade, each client machine must first obtain the new version of the software, and then uninstall and replace the old version. Each client upgrade of C/S architecture system requires the cost of human, material and financial resources for the enterprise.


b, S/b structure:

-B/s,browser/server, browser/server. b/S architecture, in fact, is a special C/s architecture, but this client specifically refers to the browser.

-For systems with B/s architecture, the client is required to have a browser installed, then the client can access the server. And the whole system upgrade, only need to upgrade the server-side program. Therefore, the system of B/s architecture has the biggest advantage is that there is no client upgrade problem.

-Because the client is not designed specifically for a particular business, it is a common client, so there is almost no ability for the client to process a specific business. And for the specific business of the processing pressure, all added to the service side, resulting in a slow operation of the server program, the responsiveness of the client is reduced, affecting the customer experience.

-In addition, there is a problem with the B/S architecture system: Browser compatibility issues. Although the client only needs a browser to access the server, but because of the browser brand, version a lot, and its implementation technology is very different, so the server needs to find a way to compatible with various browser versions. This virtually increases the pressure on the server side.


2. Roles and protocols in Web Access:

-Roles and protocols in Web Access: (There are 4 roles, browsers, Web servers, server-side programs and DB; There are 3 protocols, HTTP protocol, servlet protocol, JDBC Protocol). )

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/A7/21/wKioL1nhdqfBOhuSAACtLiebt4M811.png "title=" 00. PNG "alt=" Wkiol1nhdqfbohusaactliebt4m811.png "/>

-the so-called agreement, that is, norms, rules, communication between the parties prior to the agreement.

-The HTTP protocol requires that both the two sides, both the browser and the server, need to make requests and responses in the specified format. The other party in accordance with the agreement, that is, the prior arrangement of the information sent to the other party to parse.

-The servlet protocol requires that if a programmer is to develop a service-side program that accomplishes a particular business, it must implement a servlet interface and use SERVLETAPI for data transfer.

-The JDBC protocol requires that a server-side program to connect and manipulate the database requires the DB connection to be obtained in the manner specified in the JDBC Protocol (interface method), SQL execution, and results obtained. The implementation of the JDBC Protocol (interface) is done by the database vendor. Database-driven jar packages provided by the database vendor. So, when we connect different databases, we need to import different database-driven jar packages.

-In addition, there is the Java EE Protocol: The servlet protocol is part of the Java EE protocol. The Java EE protocol is a set of APIs for Javaweb development, with the exception of servlet protocols, JSTL protocols, JPA protocols, and so on. The most widely used version is JavaEE5.0. The JavaEE5.0 contains the Servlet2.5 protocol. The JavaEE6.0 contains the SERVLET3.0 protocol. A big difference between Servlet2.5 and the Servlet3.0 version is that Servlet3.0 supports annotated development of servlet, Filter, and listener classes.


3, the Web server tomcat related instructions:

A, a simple understanding of Tomcat:

-There are many web browsers that implement Java EE specifications in real-world applications, such as Oracle's WebLogic (need to Buy), IBM WebSphere (need to Buy), Redhat Company's JBoss (does not support servlet specification, open source free), etc. These are called heavyweight servers.

-Apache Tomcat (an open source project of the Apache Software Foundation, which can be downloaded in its website http://www.apache.org/), is only in the Java EE specification servlet/ The implementation of the JSP specification (also including El and WebSocket protocol), so is actually a lightweight server, it is open source free. Tomcat is also called a Web container, or a servlet container, but it cannot be called a Java EE container.

-Tomcat9.0 installation package and source package download image interception in the official website:

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/A7/21/wKioL1nhgIPz7lBuAAA6b3UgTYw770.png "title=" 01. PNG "alt=" Wkiol1nhgipz7lbuaaa6b3ugtyw770.png "/>


-An extension of the concept: JCP (official website for http://jcp.org), Java Community Process,java Audit community, is an open international organization, mainly responsible for standardizing and supervising the development of Java, other individuals, enterprises, The Java specification developed by the Organization must be approved by the JCP before it can be identified as the Java specification, and the founder of JCP is the sun company.

B, Tomcat installation and directory structure:

-Tomcat installation, which will unpack the package, without a wizard-style installation process. The root directory of Tomcat can be renamed after decompression.

C, Tomcat's operating environment configuration:

-After Tomcat is installed, you will need to install the JDK or JRE. For TOMCAT5 and previous versions, the JDK must be installed, and for TOMCAT6 and later versions it is possible to install only the JRE without installing the JDK.

-Configure the System environment variable java_home when installing the JDK and add its bin directory to the path variable. (Tomcat does not require additional configuration)

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/A7/21/wKioL1nhg0GAPD2yAAAIJJPT2ng803.png "title=" 04. PNG "alt=" Wkiol1nhg0gapd2yaaaijjpt2ng803.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/08/6B/wKiom1nhhcKhm9tNAAALfJtKYyI427.png "style=" float : none; "title=" 03.png "alt=" Wkiom1nhhckhm9tnaaalfjtkyyi427.png "/>

-If the system environment variable is not configured, the following error is displayed on the command line:

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/08/6C/wKiom1nhiQGRqVonAAB6UgqEkGE083.png "title=" 07. PNG "alt=" Wkiom1nhiqgrqvonaab6ugqekge083.png "/>


D, Tomcat startup and access:

-After setting up the previous environment variables, Tomcat is ready to start.

-Go to the bin directory of the Tomcat directory in the command line window and execute the startup.bat command to see the tomcat boot process. Of course, you can also find the bin directory of the Tomcat directory in the Windows window and double-click the Startup.bat file to start Tomcat. (Shutdown.bat file is off tomcat)

-You can access tomcat by typing localhost:8080 on the browser address bar.

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/A7/21/wKioL1nhhTDR87QWAABLrGbDBEU589.png "style=" float : none; "title=" 05.png "alt=" Wkiol1nhhtdr87qwaablrgbdbeu589.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/08/6B/wKiom1nhh-bzBz_eAAFFwTUO6Vg159.png "style=" float : none; "title=" 06.png "alt=" Wkiom1nhh-bzbz_eaaffwtuo6vg159.png "/>


4. The Java EE specification requires that the program structure of the Javaweb project is:

-A resource file, such as. html,. jpg, etc. can be placed directly in the directory where the current application resides, or it can be accessed in a subdirectory.

-If the WEB project contains Serlvet code, the servlet's bytecode file must reside in the subdirectory/web-inf/classes where the current application resides.

-Under/web-inf/, you can include the Web. XML configuration file, define the mapping between the request URI and the Serlvet you want to access, specify the Welcome page, and so on.

-Under/web-inf, you can include the subdirectory lib, which is used to store the external jar package used by the current WEB application.

-Resources in the/web-inf/directory cannot be accessed directly by the browser.

-As shown below:

---project root directory

---html, jsp, JS, CSS, JPG and other resource files

---sub-directories

---related resource files

---web-inf

---classes

---Lib

---web. xml

---html, JSP and other resource files


5. Interpreting Server.xml Files:

-The Tomcat server is made up of a series of configurable components that can be used in <CALTALINA_HOME> (the root directory of the Tomcat installation)/conf/ Server.xml file, each Tomcat component and a configuration element in the Server.xml file correspond to the following common elements:

A, <Server> elements: represents the entire Catalina servlet container, which is the top-level element of the Tomcat instance and can contain one or more <Service> elements.

B, <Service> elements--Deploy different applications on different ports to replicate multiple Service. (contains a <Engine> element, and one or more <Connection> elements, which share a <Engine> element.) )

C, <Connector> elements: The component that represents the actual interaction with the client, and it is responsible for receiving customer requests and returning the response results to the customer.

D, <Engine> elements--Virtual host: Each <Service> element can contain only one <Engine> element, <Engine> element processing in the same <Service> all A customer request received by the <Connector> element.

E, <Host> elements: A <Engine> element can contain multiple <Host> elements, each <Host> element defines a virtual host that can contain one or more Web applications.

F, <Context> elements--Deploying multiple applications at the same port replicates multiple Context: Each <Context> element represents a single Web application running on a virtual host, and a <Host> element can contain multiple < The context> element.

-The Server.xml element in Tomcat is detailed:

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/A7/2A/wKioL1niDWqxPPEPAANKJktVvPI640.jpg "title=" A7ac4e73-ed23-31a8-9bbe-cc48544bcfb5.jpg "alt=" Wkiol1nidwqxppepaankjktvvpi640.jpg "/>


6, the context.xml description in Tomcat, the context tag explains:

A, before tomcat5.5: the context is embodied in the <Context> element in the host in/conf/server.xml, which is defined by the context interface. Each <Context> element represents a single Web application running on a virtual host.

-Server.xml files, such as <context path= "/kaka" docbase= "Kaka" debug= "0" reloadbale= "true" >.

-Path represents the virtual directory to be created, which specifies the context root to access the Web app, such as http://localhost:8080/kaka/... DocBase: The path that is stored for the application's path or war file, either an absolute or a relative path (relative path is relative to <Host>).

-Reloadable: If this property is set to true,tomcat the server will monitor the changes in the Web-inf/classes and Web-inf/lib directory class files when running, if it is monitored to have a class file being updated, The server automatically reloads the Web reference so that we can change the application without restarting Tomcat.

-Nested any number of context elements in a host element. The path for each context must be unique and defined by the Path property. In addition, you must define a context that path= "", which the context calls the virtual host's default Web application, to handle requests that are not able to match the context path of any context.


b, after the tomcat5.5:

-It is not recommended to configure in Server.xml, but to configure it independently in/conf/context.xml. Because Server.xml is a resource that cannot be reloaded dynamically, once the server is started, to modify the file, you have to restart the server to be able to reload. The context.xml file does not, and the Tomcat server scans the file periodically. Once the file is found to be modified (timestamp changed), the file is automatically reloaded without restarting the server.

-As shown below:

    <context path= "/kaka" docbase= "Kaka" debug= "0" reloadbale= "true" privileged= "true" >
& nbsp;   <WatchedResource>WEB-INF/web.xml</WatchedResource>
    < Watchedresource>web-inf/kaka.xml</watchedresource> monitoring resource file, if Web. xml | | Kaka.xml changes, the app is automatically reloaded.
    <resource name= "Jdbc/testsiteds" indicates the specified JDBC name
    auth= "Container" Represents the authentication method, typically container
    type= "Javax.sql.DataSource"
    maxactive= "100" Maximum connections supported by connection pool
    maxidle= "30" Connection pool can be free maxidle connections
    maxwait= "10000" connection pool when the connection is exhausted , new request wait time, milliseconds
    username= "root" means database user name
    password= "root" indicates the password of the database user
    driverclassname= "com.mysql.jdbc.Driver" means jdbc Driver
    url= "jdbc:mysql:// Localhost:3306/testsite "/> means database URL address
    </Context> 


C, Appendix: Three Scope of context.xml:

-Tomcat server level: configured in/conf/context.xml.

-Host level: In/conf/catalina/${webappname}.xml, then configure.

-web App Level: Add ${webappname}.xml to/conf/catalina/$ (HostName}, then configure.




This article is from the "12392717" blog, please be sure to keep this source http://12402717.blog.51cto.com/12392717/1972421

Instructions for the Web server Tomcat (role and protocol issues in Web Access and program structure issues for Javaweb projects)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.