Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do we put the Servlets in the directory structure of Tomcat?

I copied a HelloServlet application i got from the web and put it in the ROOT folder. I ran the server and it doesn't work. What is wrong? I think its about the location of the Java classes.

like image 471
Johny_M Avatar asked Dec 11 '10 03:12

Johny_M


People also ask

Where does Tomcat store servlet files?

Compiling the servlet The servlet API jar file usually provided by the servlet container. In case of Tomcat 7.0, the jar file is placed under TOMCAT_HOME\lib directory and is named as servlet-api. jar.

Where are servlets located?

By default, a servlet application is located at the path <Tomcat-installationdirectory>/webapps/ROOT and the class file would reside in <Tomcat-installationdirectory>/webapps/ROOT/WEB-INF/classes.

Where is the default servlet configured in Tomcat?

Where is it declared? So by default, the default servlet is loaded at webapp startup and directory listings are disabled and debugging is turned off. If you need to change the DefaultServlet settings for an application you can override the default configuration by re-defining the DefaultServlet in /WEB-INF/web. xml .


2 Answers

this documentation should help you

http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html

/WEB-INF/classes/ - This directory contains any Java class files (and associated resources) required for your application, including both servlet and non-servlet classes, that are not combined into JAR files. If your classes are organized into Java packages, you must reflect this in the directory hierarchy under /WEB-INF/classes/. For example, a Java class named com.mycompany.mypackage.MyServlet would need to be stored in a file named /WEB-INF/classes/com/mycompany/mypackage/MyServlet.class.

like image 121
Aaron Saunders Avatar answered Oct 12 '22 12:10

Aaron Saunders


you have to put the web application in webapp folder in tomcat.

Also the url should be

http://localhost:8080/folder_name

like image 41
rxx Avatar answered Oct 12 '22 13:10

rxx