Deploying Web Applications

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

JSTL: JSP Standard Tag Library Kick Start
By Jeff Heaton

Table of Contents
Chapter 12.  Debugging and Deploying Tag Libraries


Installing and packaging your Web application is a critical step. Your application will not be successful if it is not easy to install. Web applications that make use of JSTL and your own custom tag libraries are distributed in exactly the same way as other Web applications. In this section, you'll learn how to create a single archive that stores all of your Web application's files.

Understanding WAR Files

A Web Archive, or WAR file, is a common means of distributing Web applications. A WAR file resembles a Java JAR file: Both have exactly the same format and are based on the Zip file format. A WAR file allows you to package all of the files that are necessary to run your Web application. This includes the JSP pages, the JAR files, and other configuration files. This file is then placed in the Web applications directory (webapps) of a JSP Web server, where it can be executed.

Although a WAR file allows you to store many of the components of your Web application, it cannot store everything. Programs that are completely external to your Web application are not stored in the WAR file. For example, the database in your database connection must be configured separately from the WAR file. The forum application uses a MySQL database to store its data.

While you are not able to store the database as part of the WAR file, the configuration settings used to connect to that database are probably stored in other configuration files. These configuration files will be stored in the WAR file.

Let's look at an example, using the forum application we created in Chapter 11. The forum application is just a directory off the ROOT directory of Tomcat. We'll move this directory to a WAR file. That way, we can distribute the forum application as one single file component that we can place on a Web server.

Creating a WAR file is relatively simple. If you know how to create a JAR file, you already know how to create a WAR file. The procedure for creating a WAR file is identical to that for creating a JAR file. The only difference is that the final output file has a .war extension rather than .jar.

If you are using a Unix system, you will likely use the following two jar commands to create the WAR file:

jar cvf forum.war /var/jakarta-tomcat-4.0.4/webapps/ROOT/example/   ch11/forum/*.jsp jar uvf forum.war /var/jakarta-tomcat-4.0.4/webapps/ROOT/WEB-INF/ 

If you are using Microsoft Windows, use the following two jar commands to create the WAR file:

jar cvf forum.war C:\Program Files\Apache Tomcat 4.0\webapps\ROOT\   example\ch11\forum\*.jsp jar uvf forum.war C:\Program Files\Apache Tomcat 4.0\webapps\ROOT\   WEB-INF\ 

For both commands, you have to change the directory slightly if you've installed Tomcat in another location.

The WAR file forum.war is shown in Figure 12.9 as a Zip file so that you can see the contents.

Figure 12.9. Creating a Zip file that becomes a WAR file.

graphics/12fig09.jpg

Distributing a WAR File

Now that you've created the Web archive, you must distribute it. Distributing a WAR file is easy. You don't have to make any changes to the Web configuration files to take advantage of the new WAR file. Copy the WAR file to the webapps directory inside Tomcat. When Tomcat is next started, this file will be expanded. The filename of the WAR file becomes part of the URL. For example, to access forum.war, you would likely access the URL http://127.0.0.1:8080/forum.

WAR files are scanned only when the Web server starts up. If you do not restart the Web server after deploying a WAR file, the Web server will never become aware of the WAR file. Figure 12.10 shows the directory structure of a Web server containing a WAR file that has been expanded by the server.

Figure 12.10. A deployed WAR file.

graphics/12fig10.jpg

You have now seen how to properly deploy a WAR file. Now, let's see how to access and test that WAR file. When you place a WAR file in the webapps directory, the contents of that file are automatically made available under a path that corresponds to the name of the archive. For example, you could access the Web archive forum.jar from the Web path http://127.0.0.1:8080/forum.


    printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
    Top

    [0672324504/ch12lev1sec3]

     
     


    JSTL. JSP Standard Tag Library Kick Start
    JSTL: JSP Standard Tag Library Kick Start
    ISBN: 0672324504
    EAN: 2147483647
    Year: 2001
    Pages: 93
    Authors: Jeff Heaton

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net