Tomcat is the servlet container that is used in the official Reference Implementation for the Java Servlet and JavaServer Pages technologies. The Java Servlet and JavaServer Pages specifications are developed by Sun under the Java Community Process.
We want to add a custom application to Tomcat called article. The first thing we have to do is edit the file conf/server.xml
<Context path="/article" docBase="article" debug="0" reloadable="true" />
Now we have to make sone directories for our application.
mkdir webapps/article mkdir webapps/article/WEB-INF mkdir webapps/article/WEB-INF/classes mkdir webapps/article/WEB-INF/lib
All *.html and *.jsp go into the directory webapps/article. All *.class files specific to our application go into webapps/article/WEB-INF/classes. All *.class files that are libraries to our application *.class files (typically *.jar files) go into webapps/article/WEB-INF/lib.
Assume we want to have a servlet that writes articles. Now we have to create the file webapps/article/WEB-INF/web.xml.
<servlet> <servlet-name>ArticleWriterName</servlet-name> <servlet-class>ArticleWriter</servlet-class> </servlet> <servlet-mapping> <servlet-name>ArticleWriterName</servlet-name> <url-pattern>/writer</url-pattern> </servlet-mapping>
Now we have to create the file webapps/article/WEB-INF/classes/ArticleWriter.java and compile it. After restarting Tomcat, we can access the servlet from http://servername:8080/article/writer.