Structure of web application
Servlet specification defines a standard structure for web applications,So that the web application run on any server irrespective of vendor.
Procedure for assembling a web-application
- Create WEB-ROOT Directory(example e:\WebApp)
- Create WEB-INF directory Under WEB-ROOT directory.
- Under WEB-INF directory create the following two directories
- lib(For storing jar files.)
- classes(For storing java classes.)
- Copy the servlet class files under WEB-INF/classes.
- Provide the deployment describer(web.xml) in WEB-INF directory
- Provide the static resources like HTML files, XML files, Image files,etc.. under WEB-ROOT directory or the sub directory of WEB-ROOT directory(except WEB-INF)
- Static resources are publicly accessible i.e end user can access these just by name across the web.
- Secured resources are not recommended to place within the WEB-ROOT directory.
- Inside WEB-ROOT , we have to maintain a folder named with WEB-INF.Until servlet 2.4 version this folder is mandatory,But from servlet 2.5 version this folder is optional.
- All the resources which are placed within the WEB-INF are not publicly accessible and can be used by web container to provide response.
- If we access any resource directly by it’s name present in WEB-INF ,we will get 404 status code.
- Secured resources should be placed within WEB-INF only.
- The classes which present in classes folder are by default available to the web container and hence it is not required to set classpath explicitly.
- We should place all dependency jar files under lib folder.
- For the required .class files web container always searches first in classes folder,if it is not available then only it will search in lib folder.
- All tld files , which are used by our web application must be placed within the WEB-INF either directly or in directly.