File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Running servlet in tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Running servlet in tomcat" Watch "Running servlet in tomcat" New topic
Author

Running servlet in tomcat

ramdas pradeep kumar
Ranch Hand

Joined: Aug 27, 2003
Posts: 36
I am new to the Tomcat. I got a servlet project from someone else.
I've deployed the war file in the webapps dir.
It extracted the files and in the web-inf/classes dir and so many sub folders have been created as per the package structure. there is one servlet class in the innermost folder.
how can i call the servlet directly
any properties need to be changed in xml files, etc
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by ramdas pradeep kumar:
I am new to the Tomcat. I got a servlet project from someone else.
I've deployed the war file in the webapps dir.
It extracted the files and in the web-inf/classes dir and so many sub folders have been created as per the package structure. there is one servlet class in the innermost folder.
how can i call the servlet directly
any properties need to be changed in xml files, etc

Hi Pradeep
Do check the web.xml file, do you find any thing like startup tag, also check for the Servlet Context in server.xml file, you mite need to add a context..
hth
MB


Malhar Barai
SOA & Java Book
Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
I believe it can be done as following:
http://localhost:8080/myapp/servlet/com.abc.test.hello.MySerlvet
hth


The secret to creativity is knowing how to hide your sources.
ramdas pradeep kumar
Ranch Hand

Joined: Aug 27, 2003
Posts: 36
hai malhar,
u mean the xml files in the config dir? can you explain me please.
i found the following in server.xml
<Context path="/examples" docBase="examples" debug="0"
reloadable="true" crossContext="true">

a segment from web.xml
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
[ September 19, 2003: Message edited by: ramdas pradeep kumar ]
ritchie diputado
Greenhorn

Joined: Sep 19, 2003
Posts: 5
Hi heres a sample xml configuration for servlet:
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>mypackage.anotherpackage.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>

Now you can call this serverlet by:
http://localhost:8080/mycontext/myservlet
Hope it helps
Ritchie Diputado
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by ramdas pradeep kumar:
hai malhar,
u mean the xml files in the config dir? can you explain me please.
i found the following in server.xml
<Context path="/examples" docBase="examples" debug="0"
reloadable="true" crossContext="true">


The context is in server.xml indeed in the "conf" directory...


a segment from web.xml
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

The web.xml in the WEB-INF directory...
The following should be your directory structure
-bin
-conf
|- server.xml
|- tomcat-users.xml
|- web.xml(x - This is on the web.xml, we hv to use...)
-...
-webapps
|- examples(Contains examples)
|- <context you define>
|- WEB-INF(inside your context)
|- web.xml(inside WEB-INF)
-...
hth
MB
[ September 19, 2003: Message edited by: Malhar Barai ]
[ September 19, 2003: Message edited by: Malhar Barai ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running servlet in tomcat