Directory Structure in Web Application

Chapter 2 - The Structure and Deployment of Web Applications

    Directory Structure in Web Application

  • Directory Structure

    Web applications use a standard directory structure defined in the Java EE specification. deploy a Web application as a collection of files that use this directory structure, known as exploded directory format, or as an archived file called a WAR file.

    The WEB-INF directory contains the deployment descriptors for the Web application (web.xml and weblogic.xml) and two subdirectories for storing compiled Java classes and library JAR files.

    These subdirectories are respectively named classes and lib. JSP taglibs are stored in the WEB-INF directory at the top level of the staging directory.

    The Java classes include servlets, helper classes and, if desired, precompiled JSPs.

    Place the static files, such as HTML files and JSP files in the directory that is the document root of the Web application. In the default installation of WebLogic Server, this directory is called DefaultWebApp, under user_domains/mydomain/applications.

    To make the Web application the default Web application, set context-root to "/" in the weblogic.xml deployment descriptor file.

    DefaultWebApp/WEB-INF/web.xml 
    

    The Web application deployment descriptor that configures the Web application.

     
    DefaultWebApp/WEB-INF/weblogic.xml 
    

    The WebLogic-specific deployment descriptor file that defines the named resources in the web.xml file are mapped to resources residing elsewhere in WebLogic Server. This file is also used to define JSP and HTTP session attributes.

    DefaultWebApp/WEB-INF/classes 
    

    Contains server-side classes such as HTTP servlets and utility classes.

    DefaultWebApp/WEB-INF/lib 
    

    Contains JAR files used by the Web application, including JSP tag libraries. The entire directory,is bundled into a WAR file using the jar command. The WAR file can be deployed alone or as part of an Enterprise application with other application components, including other Web applications, EJB components, and WebLogic Server components.

    JSP pages and HTTP servlets can access all services and APIs available in WebLogic Server. These services include EJBs, database connections through Java Database Connectivity (JDBC), JavaMessaging Service (JMS), XML, and more.

    Accessing Information in WEB-INF

    The WEB-INF directory is not part of the public document tree of the application. No file contained in the WEB-INF directory can be served directly to a client by the container.

    The contents of the WEB-INF directory are visible to servlet code using the getResource and getResourceAsStream() method calls on the ServletContext or includes/forwards using the RequestDispatcher.

    Since requests are matched to resource mappings in a case-sensitive manner, client requests for ‘/WEB-INF/foo’, ‘/WEb-iNf/foo’, for example, should not result in contents of the Web application located under /WEB-INF being returned, nor any form of directory listing thereof.

    Directory Structure Example:

    The following is an example of a Web application directory structure, in which myWebApp/ is the staging directory:

    //Web Application Directory Structure 
    myWebApp/
     WEB-INF/
      web.xml
      weblogic.xml
      lib/
       MyLib.jar
      classes/
       MyPackage/
        MyServlet.class
     index.html
     index.jsp
     

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy