Servlet & JSP (25)

Source: Internet
Author: User

Web applications are divided into two stages: development and deployment. Through deployment, components can be loosely coupled with each other, reducing the maintenance difficulty of Web applications. This article mainly discusses how to configure web programs in any directory and how to publish web programs in the form of war files. We will first discuss how to configure web programs in any directory.

Configure web programs in any directory

A Web Container can run multiple web programs. Each web program has a unique context root. How to deploy the context root is related to a specific Web container. For tomcat, each subdirectory in the webapps folder under the installation directory is an independent web application. The subdirectory name is the context root of the Web application. After we develop and compile the source code of the Web application, we will copy the program to the webapps folder. When Tomcat is started, the program in this folder is automatically loaded, so we can directly access it without other configurations. However, every time we complete a function, we need to copy the file to the corresponding directory under the webapps folder for testing, which is too cumbersome.

You can configure a virtual directory on the Web server. The actual directory corresponding to the virtual directory can be in any path. Similar configurations are also available in Tomcat. You must set the <context> element in the XML configuration file.

Classname: Specifies the Java class name that implements the org. Apache. Catalina. Context interface. If not specified, use the standard implementation org. Apache. Catalina. Core. standardcontext.

Cookie. If you want to use cookies to transmit session identifier (the client must support cookies), set it to true. Otherwise, the value is false. In this case, only the URL rewriting is used to pass the session identifier.

Crosscontext. If you want to call servletcontext. getcontext () in the application to return the request dispatcher of other web applications running on the VM, set it to true. In an environment with high security, if it is set to false, getcontext () always returns NULL. The default value is false.

Docbase, the document reference directory (document base, also known as context root) of the Web application, or the path of the war file. You can use an absolute path or an appbase path relative to the host to which the context belongs.

Path: the context path of the Web application. Catalina compares the starting point of each URL with the context path and selects an appropriate web application to process the request. The context path under a specific host must be unique. If context path.

Reloadable, If you want Catalina to monitor whether the classes under/WEB-INF/classes/AND/WEB-INF/lib change, automatically reload the web application when the change occurs, set to true. This feature is useful in the development phase, but it also greatly increases the server overhead. Therefore, it is not recommended after release. However, you can use the Manager application to trigger application overloading when necessary.

Unpackwar. If it is true, Tomcat expands all compressed Web applications before running the web application. The default value is true.

War File

If a web application contains many directories and programs, it is not convenient to deploy the web application on another machine. We can package a web application as a Web Archive (WAR) file. This process is similar to the process of packaging a Java class file into a jar file. The war file can be used to publish servlet files and related resources together.

If you use the command line to package, you can enter the doscommand and switch to the directory where the web project is located. Run the following command:

Jar-CVF project name. War *

All subdirectories and files of the project can be packaged into an archive file named project name. War. If you do not want to include the Java source file in the src directory, run the following command:

Jar-CVF project name. War *. html WEB-INF/

If you use eclipse to develop Web applications. You only need to configure the Tomcat plug-in eclipse before creating a web project. Right-click the WEB Project, select export, select Web and war file, and enter the file name and target directory to be packaged. Eclipse Tomcat plug-in is:Http://www.eclipsetotale.com/tomcatPlugin.html(Decompress the compressed package and put it
Restart eclipse in the eclipse plugins directory, and the Tomcat plug-in will be installed successfully)

Reprinted please indicate the source: http://blog.csdn.net/iAm333

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.