|
|
|
| kinetic Home | kinetic Manager | E-mail Services | Web Site Management | USENET News | Modem Pools |
| Home > Web Site Management > Java Application Server > Web Applications > Web Application Overview |
View the printer friendly version of this document |
Web Application OverviewRevised: November 16, 2004 Important: The Java application server and MySQL database are not included as part of the kinetic Service annual fee. These technologies are available on an as-requested basis for an additional fee. Contact David Drum at david@more.net or (800) 509-6673 for additional information. Contents
OverviewA Java web application is a collection of resources that function together as a complete application to perform some web-based service. These resources may include:
A Java web application is typically bundled or packaged into a Web Application Archive .war file for distribution. An installation program isn't needed for a web application because the application resources and its directory structure is inherently stored in the .war file, similar to how a .zip file can store archived files and maintain their original directory structure. The actual format of a .war file isn't special it is a Java Archive (.jar) file that was created with the Java SDK's Jar tool and saved with a .war filename extension. Managing Your Web ApplicationThe Tomcat Manager provides the ability to install, start, stop, reload, and remove your web applications. You may use the Tomcat Manager from any location with a web browser to manage your web applications. OverviewA Tomcat Manager exists for the primary (#1), failover (#2), and spare (#3) application servers (the roles of these servers are described in the Java Application Server Overview document). To visit each Tomcat Manager, type the appropriate URL in your web browser and replace {webdomain} with your website's domain name. Note that the numeral in the URL indicates the server as indicated above.
Important: You must manage your applications separately on each server since all three servers are configured to host your web applications. However, the spare server (#3) is not typically configured to accept requests unless there is a problem with the primary and failover servers, so its Tomcat Manager will not usually be available. When you attempt to visit the Tomcat Manager, a window displays with options for a username and password. This authentication provides protection so that anonymous Internet users cannot access the Tomcat Manager. For more information about managing accounts that can access the Tomcat Manager, see Managing Tomcat Manager Usernames and Passwords. If you authenticate with the correct username and password, the Tomcat Manager displays the applications that are installed and their context paths, names, running status, and the number of active sessions. Important: Once you successfully authenticate for the Tomcat Manager, you will not have to authenticate again until you close your web browser or exceed the 30 minute session timeout without interacting with the Tomcat Manager. When you are finished with the Tomcat Manager, it is best to close your web browser. This is especially important if you are using the Tomcat Manager from a shared computer. Upon successful authentication, the Tomcat Manager lists all of the web applications that you've installed with links to perform the following actions:
The Tomcat Web Application Manager How To document on the Jakarta web site provides additional details about using the Tomcat Manager. Managing Tomcat Manager Usernames and PasswordsThe Tomcat Manager uses realm-based authentication with a MySQL database. The database administrator for your organization may add, remove, and update Tomcat Manager accounts within the database. Tomcat is configured like the local development environment as documented in the Installing the Tomcat Java Application Server document. To review how to manage Tomcat Manager usernames and passwords, see the Configuring and Using the Tomcat Manager section of that document. Important: Unlike the local development environment, the customer MySQL server does NOT contain a local_realm database. For easy identification, the name of each kinetic Service customer database uses a prefix that matches the customer's web site domain name. Hence, the database for Tomcat Manager accounts is named {webdomain}_realm, where you replace {webdomain} with your web site domain. Note that since the '.' character is reserved in MySQL, all '.' characters are replaced with '_' characters in the domain name (i.e., exampledomain_k12_mo_us_realm). Installing and Starting a Web ApplicationServlet containers such as Tomcat understand that a Important: Upon a successful installation, Tomcat will automatically start your web application. For more information about stopping and starting applications that are already installed, see Stopping and Starting Your Web Application.
Stopping and Starting Your Web ApplicationCircumstances occur when you must stop and start your web application with the Tomcat Manager. Stopping the application prevents it from running and being accessible with your web site. For example, it is common to stop your web application when it must be inaccessible for troubleshooting existing problems and when the web application must be updated with new source files. Follow these steps to stop your web application:
To start your web application, visit the Tomcat Manager for the primary server, click the Start link that is located to the right of your web application's name, and then repeat these steps for the failover server. Note: The Start link is not available unless the web application is already stopped. Removing Your Web ApplicationCircumstances occur when you must remove your web application with the Tomcat Manager. For example, it is common to remove your web application when you need to update it with a new .war file or to permanently remove the web application because it is no longer needed. Follow these steps to remove your web application: Important: Be careful with the Tomcat Manager's remove command! It removes the directory structure that was created when you installed your web application.
Updating Your Web ApplicationUp to three application servers can be using the files in a web application at the same time. Although the web application files exist in one web application directory, the use of three server requires special care when you update your web applications. Follow these tips to ensure that updates to your applications work properly:
Web Application Directory StructureA web application exists in a servlet container as a hierarchy of directories. The root of the application directory may contain public documents and JavaServer Pages (JSPs). The application developer may place these files in other directories as well, such as organizing all of the graphic images into a /graphics directory or some other organization structure. Although most of the directory names in an application are up to the discretion of the developer, the /META-INF and /WEB-INF directories are inherent to all web applications. The /META-INF directory contains information about the WAR file. This directory and its contents are created by the JAR tool when the WAR file is created and it is extracted when the WAR file is installed. You need not worry about this directory or its contents, such as the manifest.mf file that contains information about the WAR file. Like the contents of the /WEB-INF directory detailed below, the contents of the /META-INF directory are not public and cannot be served by the web server or application server.
The /WEB-INF directory contains all of the things related
to the application that are not public and cannot be served by
the web server or application server. The following subdirectories and files exist in this
directory:
Web.xml -- Web Application Deployment DescriptorUse the web.xml deployment descriptor file to configure a web application. The Tomcat servlet container reads this file when it loads your web application. It is an XML document which uses predefined tags from a rule set. Note: The document XML in 10 points highlights the premises of XML. An XML tag has the following format: <element attribute1="value1" attribute2="value2" ...> </element> If you have hand-coded HTML, this may look familiar. However, unlike HTML, XML tag syntax is strictly enforced. Every opening tag must be closed by a corresponding closing tag (< /element>) or it must be self-closed with /> at the end of the tag. Unlike HTML, XML is case-sensitive. Another obvious differentiation with HTML is that XML documents must contain an XML declaration as the first tag on the page. An example is shown later in this document. One of the useful things about XML is that you can specify a rule set in another document for validating the XML. This rule set document is called the Document Type Definition (DTD). A DTD is not mandatory for every XML document. However, it is mandatory to verify that an XML document is valid (i.e., adheres to a rule set). This is particularly important when XML documents contain data that must be shared between disparate systems, and the systems must agree on a format for the data. This applies to web.xml since it is validated by a servlet container and thus it has a DTD. Although the finer details of DTD construction are too vast to document here, you should understand a few basic concepts before you dive into authoring a web.xml file for an application. You may frequently refer to the web application deployment descriptor DTD; understanding its structure will help. Three key concepts include:
Web.xml SpecificsAs shown below, every web.xml must have the following header information that identifies it as an XML document and details the location of the DTD. The DTD location is specifically referenced in the Java Servlet Specification Version 2.3 from Sun.
For a complete reference to the web.xml DTD, please refer to the web-app_2_3.dtd on Sun's web site. This DTD is also described in the Java Servlet Specification. You'll find many descriptive comments in the DTD since it contains comments in the form of <!-- comment --> just like standard HTML. Within the DTD you'll see the following declaration: <!ELEMENT web-app (icon?, display-name?, description?, distributable?, context-param*, servlet*, servlet-mapping*, session-config?, mime-mapping*, welcome-file-list?, error-page*, taglib*, resource-ref*, security-constraint*, login-config?, security-role*, env-entry*, ejb-ref*)> As mentioned earlier, the DTD defines the valid elements and the structure of the XML documents that reference the DTD. Three important concepts are related by the above declaration:
Some of the most common elements used for configuring a web application are detailed in the sections below. Important: Remember that the relative order of the elements is important. Also, the examples below include "..." to denote that other elements may exist above and below the example code. Do not place these in your final configuration files. <web-app><web-app> is the root element. All of the other elements that configure your web application are nested within the opening <web-app> and closing </web-app> tags. <display-name>Use the <display-name> tag to provide the name of the web application. Only one <display-name> tag should exist as an element within the <web-app> parent element. This element is used by the Tomcat application manager as the name of the application.
<description>Use the <description> tag to provide descriptive text about the web application. Only one <description> tag should exist as an element within the <web-app> parent element.
<welcome-file-list> and <welcome-file>Use the <welcome-file-list> element to specify one or more of the application's files that should be displayed when a URL requested by an end user only indicates a directory. Each file is specified in a <welcome-file> element, and the <welcome-file-list> is the parent element for all of the <welcome-file> elements. The order of the <welcome-file> elements makes a difference the servlet container searches the requested directory for the welcome files from first to last and stops when it finds one of the files.
Important: These elements are not especially useful on a production server. The Apache web server determines if HTTP requests should be handled by it or Tomcat, and it only forwards requests to Tomcat for .jsp files, servlets (the URI contains /servlet), and Struts .do files. HTTP requests that only indicate a directory are not forwarded to Tomcat. To ensure that requests that only specify a directory are properly forwarded to Tomcat, you can add an index.shtml file in the root of your web application. In this file, use Apache's Server-Side Include (SSI) statement to include the .jsp or servlet that you want to invoke for your application. Apache will process the SSI due to the .shtml file extension and then include the appropriate file from your web application. For example, the following examples use SSI to include a .jsp and a servlet:
<session-config> and <session-timeout>Use the <session-config> element to specify the session timeout value for all sessions created in this web application. If the session does not have any activity for this time, it is considered an expired session. <session-config> is the parent element of and requires the <session-timeout> subelement. The timeout value must be expressed as an integer in minutes, such as the 10 minute timeout in the example below.
<error-page>, <error-code>, <exception-type>, and <location>Use the <error-page> element to map one or more resources in the web application to an error code or exception type. This functionality is similar to the error page ability provided by the JSP page directive, but allows finer control. <error-page> is a parent element to the <error-code>, <exception-type>, and <location> elements; each <error-page> element must contain the <location> element and either an <error-code> or <exception-type> element. The <error-code> contains an HTTP error code, such as 404. The <exception-type> contains a fully qualified class name of a Java exception type. The <location> element defines the resource, such as a JSP, that is displayed when the corresponding error occurs.
<taglib>, <taglib-uri>, and <taglib-location>When an application uses a custom JSP tag library, each JSP that uses the taglib's custom tags must reference the taglib's Tag Library Description file (TLD). This is possible by two methods. Each JSP requires a taglib directive at the top of the page that declares that the page uses a custom taglib, provides a unique URI to the taglib's TLD, and identifies a prefix used for all custom tags within the page. The JSP author may specify the actual location of the TLD, relative to the root of the application, in the taglib directive like the example below: <%@ taglib uri="/WEB-INF/scrape.tld" prefix="scrp" %> The author may not have chosen this method, however, since it isn't flexible for reorganizing an application's directory structure. Perhaps the author expected changes in the structure of the application and didn't want to modify every the taglib directive in every JSP that used the custom taglib. In this case, the author may have chosen the more flexible method--specify some URI in the taglib directive of the JSP, and then map that URI to the TLD by using the <taglib>, <taglib-uri>, and <taglib-location> elements in the application's web.xml configuration file. The <taglib-uri> and <taglib-location> are required subelements of the <taglib> element. For example, the taglib directive in the JSP could be: <%@ taglib uri="/scrapeTags" prefix="scrp" %> In this case, the web.xml configuration file might contain the following elements:
By specifying the TLD location with the <taglib-location> element in web.xml, the TLD will be mapped to /WEB-INF/scrape.tld for every JSP in the web application that specifies the /scrapeTags URI in a taglib directive. <mime-mapping>, <extension>, and <mime-type>Web servers are configured to associate MIME types with file extensions. When a web server forwards a request for an application to a servlet container, the application is responsible for setting the MIME type of the response. Typically this is not an issue since servlet containers know that content generated by JSP and servlets is the text/HTML MIME type. However, developers that provide other types of documents as responses in their applications may set other MIME types with the <mime-mapping> element. <mime-mapping> must include the two required subelements <extension> and <mime-type>. The example below specifies the correct MIME type for a PDF file:
|
|
kinetic Home |
kinetic Manager |
E-mail Services |
Website Management |
USENET News |
Modem Pools Copyright © 2002-2009 Curators of the University of Missouri. All rights reserved. Copyright, accessibility, privacy and other information about this site. DMCA and other copyright information. Acceptable Use Policy |