Source: CCID >> World >> JAVA technology Author: Jason Brittain & Ian F. Darwin Translator: Chen issued a document time: 2004.11.08
Editor Press: Now developing Java web applications, establishing and deploying Web content is a very simple job. People who use Jakarta Tomcat as servlets and JSP containers have spread all over the world. Tomcat has many features such as free, cross-platform, and is updated very quickly, and now very popular.
What you need to do is: Configure Tomcat according to your needs, as long as you are configured correctly, Tomcat is generally suitable for your request. I hope to help you.
1. Configuration System Management (Admin Web Application)
Most commercial J2EE servers provide a powerful management interface, and most of the easy-to-understand web application interfaces. Tomcat also provides a mature management tool in its own way, and is not inferior to those commercial competitors. Tomcat's admin Web Application initially appeared at version 4.1, the functionality included managing Context, Data Source, User, and Group. Of course, you can also manage multiple database management like initialization parameters, User, Group, and Role. In subsequent versions, these features will be extended, but existing features are very practical.
Admin Web Application is defined in the automatic deployment file: Catalina_Base / WebApps / Admin.xml. (Translator Note: Catalina_base is the server directory under Tomcat installation directory)
You must edit this file to determine that the DocBase parameter in Context is an absolute path. That is, the path of Catalina_Base / WebApps / Admin .xml is an absolute path. As another choice, you can also delete this automatic deployment file, and create a Context of an Admin Web Application in the server.xml file, the effect is the same. You can't manage the application of Admin Web Application. In other words, in addition to deleting Catalina_Base / WebApps / Admin.xml, you may not do anything.
If you use UserDatabaseRealm (default), you will need to add a USER and a role to the catalina_base / conf / tomcat-users.xml file. You edit this file, add a Role called "admin" to the file, as follows:
You also need to have a user, and the role of this user is "admin". To add a user, add a user (changing the password safer):
When you complete these steps, restart Tomcat, access http: // localhost: 8080 / admin, you will see a login interface. Admin Web Application adopts a safe mechanism based on container management and uses a Jakarta Struts framework. Once you log in to the management interface as a "admin" role, you will be able to configure Tomcat using this management interface.
2. Configuring Application Management Manager Web Application Let you perform some simple web application tasks through a user interface than Admin Web Application.
Manager Web Application is defined in an automatic deployment file:
Catalina_base / WebApps / Manager.xml.
You must edit this file to make sure the CONTEXT's DocBase parameter is an absolute path, that is, the absolute path of Catalina_Home / Server / WebApps / Manager. (Translator Note: Catalina_Home is Tomcat Installation Directory)
If you are using UserDatabaseRealm, then you need to add a role and a user to the Catalina_base / conf / Tomcat-users.xml file. Next, edit this file, add a role named "Manager" to the file:
You also need a user with a role "manager". To add a new user like the already existing users (change your password safer):
Then restart Tomcat, access http: // localhost / manager / list, you will see a very simple text-type management interface, or visit http: // localhost / manager / html / list, you will see an HMTL management interface . No matter which method, your Manager Web Application is now launched.
Manager Application allows you to install new web applications on the basis of system management privileges for testing. If we have a new web app under / home / user / hello, and want to install it to / hello, in order to test this app, we can do this, enter "/ hello" in the first file box (As the path when access, enter "File: / Home / User / Hello" in the second text box (as a config URL).
Manager Application also allows you to stop, restart, remove, and redeploy a web application. Stop an app that can't be accessed, when some user tries to access this stopped app, will see a 503 error? "503 - this Application IS Not Currently Available".
Remove a web application, just delete the app from Tomcat's running copy, if you restart Tomcat, the deleted application will appear again (that is, removal does not mean 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 content of this web) to the Catalina_Base / WebApps directory.
2> Establish an XML fragment file that includes Context content and put the file in the catalina_base / webapps directory. This web application itself can be stored anywhere on the hard disk.
If you have a WAR file, if you want to deploy it, you just need to copy the file into the Cataalina_base / webapps directory, the file must be ".war" as an extension. Once the Tomcat monitors this file, it will (default) until the file is made as a subdirectory, and the file name of the WAR file as the name of the subdirectory. Next, Tomcat will create a context in memory, just like you have established in the server.xml file. Of course, other required content will be obtained from DefaultContext in Server.xml. Another way to deploy web applications is to write a context XML fragment file, then copy the file to the catalina_base / webapps directory. A Context fragment is not a complete XML file, but is just a context element, as well as the corresponding description of the application. This piece of fragment is like the Context element cut from Server.xml, so this piece is named "Context Disclosure".
For example, if we want to deploy a application called MyWebapp.war, the app uses Realm as an access control method, we can use this piece:
Context fragment for deploying myWebapp.war
->
Debug = "0" privileged = "true"> ResourceEName = "UserDatabase" /> Context> Name this piece "MyWebApp.xml" and copy it to the catalina_base / webapps directory. This Context snippet provides a convenient way to deploy web applications, you don't need to edit server.xml unless you want to change the default deployment feature, you don't need to restart Tomcat when installing a new web application. 1 2 3 Next >>