Java web application structure using tomcat

To qualify as a web application in j2ee we have some set of rules that has to be there in web application. The application has some folder

The below image shows the folder structure of java based application. Here we will each of them one by one.


Web-application folder

This is your web application name which we are going to develop, you can give any name as you required.

WEB-INF folder

This is the mandatory folder for java web application. The WEB-INF folder has to be there in java based web application. We will keep all the configuration and java classes’ related folder inside WEB-INF folder like classes, lib and other folders.

Classes folder inside WEB-INF

There should be a classes folder inside WEB-INF directory of your web application. The classes folder contains all complied java classes.

Lib folder inside WEB-INF

There should be lib folder inside WEB-INF folder of your web application. All the external dependency jar files for web application should be copied in lib folder.

Src folder inside WEB-INF

The src folder is optional inside WEB-INF. It is not advisable to put any src folder in WEB-INF. Your source should not be the part of WEB-INF folder, Better you keep outside all the java source files and complied files should be copied inside classes folder of WEB-INF folder.

Other folder inside WEB-INF

You can put some other folder in Web-INF folder which can be used to put some common types of files like custom tags tld files, spring configuration file, hibernate configuration and hbm files.

Web.xml inside WEB-INF

Your java based application must have WEB-INF folder and web.xml file must be there in WEB-INF folder. If web.xml is missing your web application will not be register as web application.

Web.xml also called as deployment descriptor.

The web.xml should have web-app as root context. And you can define the other server resource like servlet, filter, and listener in web.xml file.

Below is sample web.xml file for java based web application.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=""

    <!--  For displaying web application name-->
    <display-name>java web application</display-name>
    <!--  Desscription of web application -->
    <description>Test application</description>
        Application specific paramater which will be available across the
        <description>Test param</description>
    <distributable />

Outside WEB-INF folder contains

You can put web resource outside WEB-INF folder like plan html pages, plan text files, jsp files.