Packaging Web Applications

All Web components are packaged together into a standard file, a Web Archive (WAR) file, which can be deployed into the Web container. A WAR file is a type of JAR file that can be created using the jar utility. It contains both server-side classes, such as servlets, JavaBeans, JSP, and taglibs, and client-side contents, such as applets, HTML, and images. The directory structure of a WAR file looks like Figure 7.2 illustrated earlier today.

When creating a WAR file, arrange the directory according to the structure in Figure 7.2, and then issue the jar command from the application's home directory:

						jar -cvf  mywebapp.war *
					

The web.xml file is the standard Web deployment descriptor, and weblogic.xml is the vendor-specific deployment descriptor for the WebLogic Server. The subdirectory classes is used to store server-side Java classes such as servlets, whereas the lib subdirectory is used to store all the other JAR files, such as for JavaBeans.

The web.xml file describes each Web component used in the WAR file and the relationships between them. Here's an example of a web.xml that describes some of the components developed today:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//
DTD Web Application 1.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
  <servlet>
    <servlet-name> URSControllerServlet</servlet-name>
    <servlet-class>myWebApp.URSControllerServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name> URSControllerServlet </servlet-name>
    <url-pattern>/URSControllerServlet </url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>welcome.html</welcome-file>
  </welcome-file-list>
  <error-page>
    <error-code>404</error-code>
    <location>/errorPage.jsp</location>
  </error-page>
  <!-- Tag Library Descriptor -->
  <taglib>
    <taglib-uri>/welcome</taglib-uri>
    <taglib-location>/WEB-INF/tlds/welcome.tld</taglib-location>
  </taglib>
</web-app>

When the Web container start deploying the WAR file, it first reads the contents of the web.xml file and uses them as a road map to its target components.

In the preceding example of web.xml, each servlet must be defined by its name and full class name (includes the package). Servlet mapping is the concept of mapping a servlet name to a URL, which used by the container to translate requests to particular servlet. For instance, in WebLogic, the URL http://localhost:7001/mywebapp/URSControllerServlet will map the request to the URSControllerServlet servlet. In JBoss, the request http://localhost:8080/mywebapp/URSControllerServlet will have the same effect.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.253.223