In several chapters of this book, we’ve looked at the locations in which the various files must be placed. In the chapter on custom tags, for example, you saw that Tag Files must be deployed in /WEB-INF/tags or a subdirectory, or in a JAR file under /META-INF/tags or a subdirectory. If you put a Tag File anywhere else, the Container will either ignore it or treat it as static content ready to be served.
The Servlet and JSP specs have a lot of picky rules about where things go, and you really do need to know most of them. Since we’ve already covered most of this in one way or another, we use these first few pages as a test of your memory and understanding. Don’t skip it! Treat these next few pages as practice exam questions!
There are no Dumb Questions
Sharpen your pencil
Name the directories
Write the correct directory names in, given the files shown within those directories. Everything in here has been covered in an earlier chapter, but don’t worry if you haven’t completely memorized them all yet. This is the chapter where you have to burn it in.
Sharpen your pencil
Draw the directory and file structure
Look at the following web app description and draw a directory structure that supports that web app. Be sure to include the files too. There may be more than one way to structure this; we recommend using the simplest (i.e. least number of directories) to organize it.
Application name: Dating
Static content and JSPs: welcome.html, signup.jsp, search.jsp
Servlets: dating.Enroll.class, dating.Search.class
Custom tag handler class: tagClasses.TagOne.class
TLD: DatingTags.tld
JavaBeans: dating.Client.class
DD: web.xml
Support JAR files: DatingJar.jar
BE the Container
What’s wrong with this deployment? There are several things here that do not follow the Servlet or JSP specification for where they should be placed. Assume that all files have the correct names and extensions.
List everything that’s wrong with this picture:
Sharpen your pencil: Answers
Name the directories
To deploy a web app successfully, you MUST follow this structure. WEB-INF must be immediately under the application context (“MyTestApp” in this example). The “classes” directory must be immediately inside “WEB-INF”. The package structure for the classes must be immediately inside “classes”. The “lib” directory must be immediately inside “WEB-INF”, and the JAR file must be immediately inside “lib”. The “META-INF” directory must be immediately inside the JAR, and TLD files in a JAR must be somewhere under “META-INF” (they can be in any subdirectory, and “TLDs” is not required as a directory name). TLDs that are NOT in a JAR must be somewhere under “WEB-INF”. Tag Files (files with a .tag or .tagx extension) must be somewhere under “WEB-INF/tags” (unless they’re deployed in a JAR, in which case they must be somewhere under “META-INF/tags”).
Sharpen your pencil: Answers
Draw the directory and file structure
The only things that could be different in this picture are 1) the static content and JSPs could be in a subdirectory under “Dating”, or hidden under “WEB-INF” and 2) the DatingTags.tld could be in a subdirectory of WEB-INF.
Application name: Dating
Static content and JSPs: welcome.html, signup.jsp, search.jsp
Servlets: dating.Enroll class, dating.Search class
Custom tag handler class: tagClasses.TagOne class
TLD: DatingTags.tld
JavaBeans class: dating.Client class
DD: web.xml
Support JAR files: DatingJar.jar
The directory structure of a web app is intense. And everything has to be in exactly the right place. Moving a web app can hurt.
But there’s a solution, called a WAR file, which stands for Web ARchive. And if that sounds suspiciously like a JAR file (Java ARchive), that’s because a WAR is a JAR. A JAR with a .war extension instead of .jar.