Tomcat configuration tips Top 10 (1)

Source: Internet
Author: User
From: SCID> technology world> JAVA
Author: Jason Brittain & ian F. Darwin Translator: Chen guang published at: 2004.11.08
Editor's note:Developing Java Web applications now makes it easy to create and deploy web content. People who use Jakarta Tomcat as Servlet and JSP containers all over the world. Tomcat has many features such as free and cross-platform, and is very popular nowadays.

All you need to do is: Configure Tomcat according to your needs. As long as you configure it correctly, Tomcat is generally suitable for your requirements. Hope to help you.

1. Admin Web Application)

Most commercial J2EE servers provide a powerful management interface that is easy to understand. Tomcat provides a mature management tool in its own way, and is no inferior to its competitors. The Admin web application of Tomcat was first available in version 4.1. The functions at that time included management context, data source, user, and group. Of course, you can also manage databases such as initialization parameters, user, group, and role. In subsequent versions, these functions will be greatly extended, but the existing functions are very practical.

Admin web application is defined in the automatic deployment file catalina_base/webapps/admin. xml. (Translator's note: catalina_base is the server directory under the tomcat installation directory)

You must edit this file to make sure that the docbase parameter in context is an absolute path. That is to say, the path of catalina_base/webapps/admin. XML is an absolute path. As another option, you can also delete the automatic deployment file, and set up an Admin web application context in the server. xml file. The effect is the same. You cannot manage the Admin web application. In other words, you may not be able to do anything except to delete catalina_base/webapps/admin. xml.

If you use userdatabaserealm (default), you will need to add a user and a role to the catalina_base/CONF/tomcat-users.xml file. Edit the file and add a role named "admin" to the file, as shown below:


     
      <role name="admin"/>
     

You also need a user whose role is "admin ". Add a user as an existing user (change the password to make it more secure ):


     
      <user name="admin" password="deep_dark_secret" roles="admin"/>
     

After completing these steps, restart Tomcat and access http: // localhost: 8080/admin. You will see a logon interface. Admin web application adopts the container-based security mechanism and uses the Jakarta Struts framework. Once you log on to the management interface as a user of the "admin" role, you can use this management interface to configure tomcat.

2. Configure Application Management (Manager Web Application)

Manager Web application allows you to execute some simple web application tasks through a simpler user interface than Admin web application.

The Manager Web application is defined in an automatic deployment file:
CATALINA_BASE/webapps/manager. xml.

You must edit this file to ensure that the docBase parameter of context is the absolute path, that is, the absolute path of CATALINA_HOME/server/webapps/manager. (Translator's note: CATALINA_HOME is the tomcat installation directory)

If you are using UserDatabaseRealm, you need to add a role and a user to the CATALINA_BASE/conf/tomcat-users.xml file. Next, edit the file and add a role named "manager" to the file:


     
      <role name=”manager”>
     

You also need a user with the role "manager. Add a new user as an existing user (change the password to make it safer ):


     
      <user name="manager" password="deep_dark_secret" roles="manager"/>
     

Restart Tomcat and access http: // localhost/manager/list. A simple text management interface or http: // localhost/manager/html/list. A management interface of HMTL is displayed. Either method indicates that your Manager Web Application has been started.

The Manager application allows you to install new Web applications for testing without the privileges of system management. If a new web application is located under/home/user/hello and you want to install it under/hello, we can do this to test the application, in the first file box, enter "/hello" (as the path for access), and in the second text box, enter "file:/home/user/hello" (as the Config URL ).

The Manager application also allows you to stop, restart, remove, and redeploy a web application. Stopping an application makes it inaccessible. when a user attempts to access the application, a 503 error is displayed ?? "503-this application is not currently available ".

To remove a web application, the application is deleted from the running copy of Tomcat. If you restart tomcat, the deleted application will appear again (that is, removal does not mean deletion from the hard disk ).

3. Deploy a web application

There are two ways to deploy Web Services in the system.
1> copy your war file or your web application folder (including all the content of the Web) to the $ catalina_base/webapps directory.
2> Create an XML fragment file that only contains context content for your web service and put the file in the $ catalina_base/webapps directory. This web application can be stored anywhere on the hard disk.

If you want to deploy a war file, simply copy the file to the catalina_base/webapps directory. The file must use ". War" as the extension. Once Tomcat listens to this file, it will (by default) unbind the package as a sub-directory and use the war file name as the sub-directory name. Next, Tomcat creates a context in the memory, as if you have created a context in the server. xml file. Of course, other necessary content will be obtained from defaultcontext in server. xml.

Another way to deploy a web application is to write a Context XML fragment file and copy the file to the CATALINA_BASE/webapps directory. A Context fragment is not a complete XML file, but a context element and the corresponding description of the application. This type of fragment file is like the context element removed from server. xml. Therefore, this fragment is named "context fragment ".

For example, if we want to deploy an application named MyWebApp. war, which uses realm as the access control method, we can use the following piece:


     
      <!-- Context fragment for deploying MyWebApp.war --> <Context path="/demo" docBase="webapps/MyWebApp.war" debug="0" privileged="true"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Context>
     

Name the clip "MyWebApp. xml" and copy it to the CATALINA_BASE/webapps directory.

This context snippet provides a convenient way to deploy web applications. You do not need to edit the server. xml, unless you want to change the default deployment feature, you do not need to restart Tomcat when installing a new web application.

1 2 3 next page>

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.