Basic knowledge of Java Web Foundation 1Tomcat Server

Source: Internet
Author: User
Tags tomcat server

I. Tomcat installation (1) Install the JDK first and configure the environment variable Java_home. The configuration of the Tomcat server requires the JAVA_HOME environment variables of the JDK. and add%java_home%/bin to the system path variable. (2) Download and install the Tomcat installation file and configure the Catalina_home environment variable. (3) test whether the installation is successful, open Tomcat/bin startup.sh, run the server. Enter http://localhost:8080 in the browser. The cat succeeded when he came out. Two. Eclipse Configuration tomcat (1) Download eclipse, unzip it, do not need to install. (2) Eclipse adds Tomcat, opens the Eclipse work interface, selects Windows->preferences->server->runtimr->add to add the Toomcat version, and fills in the Tomcat path. (3) success. Three. Tomcat basic configuration Tomcat was started based on the configuration of Server.xml. root directory under Conf/server.xml.server.xml tags are:
server>,<Service>,<Connector>,<Engine>,<Host>,<context >,<logger>,<Value>, One of the most important connector tags, it has the following properties:

<Connector> Elements

<Connector> is a component that interacts directly with the user and is responsible for accepting user requests and returning response results to the customer.

In the connector tag in server.xml, you can configure the number of threads in the server, the maximum number of connections, waiting time-outs, and so on.

Property Description:

Property

Description

Port

The port that the connector listens on. In the browser, you can submit to the corresponding Connector by entering Url:port . Because the default port of the browser is 80, if you set the port of connector to 80, you can access it directly using the URL without having to follow a port number behind.

Protocol

Set HTTP protocol, default is http/1.1

MinThreads

Number of threads created at server startup to process user requests

MaxThreads

The maximum number of threads that can be created to process user requests

Minsparethreads

Minimum number of spare threads

Maxsparethreads

Maximum number of standby threads

Acceptcount

When all the threads that can be used to process the request are exhausted , the number of requests that can be placed in the processing queue is not processed and the Connection refused error is returned.

Redirectport

the port number that the server is redirecting after receiving an SSL transfer request when it is processing an HTTP request . (That is, when the request is HTTPS, it is forwarded to the port)

Enablelookups

If true to support domain name resolution, DNS queries can be made in the Web app by calling Request.getremotehost () to obtain the actual hostname of the remote client; DNS Query, but returns its IP address. The default value is true.

ConnectionTimeout

The number of times to wait for a timeout (in milliseconds), or 1 to indicate that the client connection time is not limited.

Four. Tomcat Server virtual directory mapping after the development of Web applications, if you want to be accessible to the outside world, you need to give the Web application directory to the Web server management, this process is called virtual directory mapping

The Tomcat server automatically manages all Web applications under the WebApps directory and maps it to a virtual directory.

You only need to put the written items in the Tomcat Server WebApps directory, the outside world can directly access.

For example: Copy the Javawebdemoproject from the F-disk Javaweb application directly to the Tomcat server WebApps directory, as shown in:

At this point the Tomcat server automatically maps a virtual directory "/javawebdemoproject" with the same name to the Javawebdemoproject javaweb application, and can then use the browser to access the resources of the Javaweb app.

Five. Interaction between the browser and the server (1) The browser sends an HTTP message: The browser sends HTTP traffic to the server, the software on the server listens to the appropriate port, and the HTTP request body (data stream) HTTP request message is the Web resource that the browser tells the W server to access under which Web application in the server. The form is as follows: Among them, the HTTP request body, accept/user-agent/host/connection and other attributes, are automatically generated by the browser. In other words, the browser automatically generates an HTTP header. About the browser automatically generated HTTP header, you can refer to the answer http://www.zhihu.com/question/34603729 (2) The server received an HTTP request message, return the HTTP response message server received the data transmitted by the browser, Begins parsing the received data, parsing " get/javawebdemo1/1.jsp http/1.1"Inside the content, know that the client browser is going to access the JavaWebDemo1Application inside the 1.jspThis web resource, and read 1.jspThe contents of this Web resource are then transmitted to the browser as stream (stream), as shown in the following: (3) The browser gets an HTTP response message and parses it.

Data sent back by the server:

1http/1.1 OK 2server:apache-coyote/1.1 3content-type:text/html;charset=iso-8859-1 4content-length:102 5date:mon, 14:25:14 GMT 6 7
(4) Browser reading of static resources note: If the HTTP response message, the returned HTML code contains JPG,CSS,JS and other static resource files. The browser then renders the HTML code while the HTTP request is sent again to obtain these static resources. For example, the HTML code returned by the server includes
Image
Http://static.ak.fbcdn.net/rsrc.php/z12E0/hash/8q2anwu7.gif
Http://static.ak.fbcdn.net/rsrc.php/zBS5C/hash/7hwy7at6.gif
...
CSS style Sheets
Http://static.ak.fbcdn.net/rsrc.php/z448Z/hash/2plh8s4n.css
Http://static.ak.fbcdn.net/rsrc.php/zANE1/hash/cvtutcee.css
...
JavaScript files
Http://static.ak.fbcdn.net/rsrc.php/zEMOA/hash/c8yzb6ub.js
Http://static.ak.fbcdn.net/rsrc.php/z6R9L/hash/cq2lgbs8.js
Reading these static files will go through a process similar to reading HTML code. It is necessary to remember that these static resources, the browser can cache them. The server's response message contains the duration of the static file. This allows you to read these static resources in the browser memory the next time the browser accesses the same Web page, which speeds up page reads. Summary: The server first returns the HTML code, and the browser then requests the static resources again. Two steps. Browser and server interaction process, specifically http://www.360doc.com/content/13/0809/16/13264825_305872743.shtml six. Tomcat The jar package is under the Tomcat root Lib folder, and all jar packages are available for all applications on the server. What are the benefits of a jar package placed under Web-inf compared to Tomcat? Tomcat automatically loads the jar package under Web-inf/lib. In Tomcat's Lib directory, these jars are all shared by all deployed applications, and are used independently by Web-inf under separate application. If you put it under Tomcat, there may be multiple apps that have dependencies on different versions of a project, which can be difficult to handle at this time. After all, ClassLoader can only load one copy.

Seven. The structure of the Web application A diagram illustrates the solution

Pictures from http://www.cnblogs.com/xdp-gacl/p/3734395.html, thanks to the author

Basic knowledge of Java Web Foundation 1Tomcat Server

Related Article

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.