I want to run JSP files using the Tomcat server, where should I place my JSP files?

Byron Tymvios

Under the Tomcat root directory there will be a sub-directory named web-apps, all web applications running on this Tomcat server will reside there. Each web application will have it's own sub-directory under web-apps, so you could create a directory for your web application under the web-apps directory like so <TOMCAT-ROOT>/web-apps/<YOUR-WEB-APP-DIRECTORY>. JSP pages can be placed insisde the directory you have created or in other sub-directories you might like to create, however please note that for each new sub-directory you place your JSP files in the URL to access them will need to include each directory.


Under the WEB-INF directory you can create another directory named classes, all your java classes used in your web application should be placed in here, in a tree structure that resembles their packages, for example: if you have a class named MyClass whose package is com.xyz then the class should be placed in <TOMCAT-ROOT>/web-apps/<YOUR-WEB-APP-DIRECTORY>/WEB-INF/classes/com/xyz/MyClass.class. Another alternative to handling classes in this way is to package them all in a jar file, the jar file can be placed in a directory named lib also under the WEB-INF directory, for example: say you have a jar file named myLibrary.jar, it can be placed in <TOMCAT-ROOT>/web-apps/<YOUR-WEB-APP-DIRECTORY>/WEB-INF/lib/myLibrary.jar. By placing classes and jar files in these directories Tomcat ensures they are on the CLASSPATH when you run your application.
