my dog learned polymorphism*
The moose likes Servlets and the fly likes How to Deploy servlet using Tomcat 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "How to Deploy servlet using Tomcat 5" Watch "How to Deploy servlet using Tomcat 5" New topic
Author

How to Deploy servlet using Tomcat 5

AsifAimen Iqbal
Greenhorn

Joined: Mar 06, 2009
Posts: 9
Hi All,
I m practically new to Servlets.I have written a servlet and i want to deploy it.I m using Tomcat 5 , Jdk 1.5 on windows vista, can any one tell me how to set the classpath and all to compile my servlet.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to the javaranch. coming to your question please go to tomcat installation directory and read \webapps\tomcat-docs\deployer-howto.html and \webapps\tomcat-docs\setup.html
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

There's more to running a servlet than just compiling a single class. Web applications have a fairly complex structure, defined by the WAR architecture specification. So the first thing you need to to is build a WAR. You'd normally want to use some sort of tools to do this, such as Ant or Maven. Some people let their IDEs do all the work, although that's a very poor alternative.

Once you've built a WAR, you need to deploy it. The Tomcat website has very good documentation on WARS and their configuration and deployment. Tomcat itself supports both standards-compliant WAR files and so-called "exploded" WARS, which are whay you'd get if you unzipped a WAR file. There's a "webapps" directory where Tomcat normally expects to put these things, although Tomcat can also find WARs and exploded WARs in other places when configured to do so.

If this sounds like a way to politely say RTFM, well, it is. There's more to the process than we can take the time or space to explain here, so the best we can do is help you find good materials for study. The Tomcat docs at http://tomcat/apache.org are pretty good, but you'd probably want to find some good books on J2EE/JEE and find some local people who know it already and are willing yo help out. Bribery is always useful.


Customer surveys are for companies who didn't pay proper attention to begin with.
greeshma reddi
Greenhorn

Joined: Feb 02, 2009
Posts: 5
To start from the beginning ...to set the classpath go to the directory where you have deployed tomcat/lib/common/ and copy the address to the environment variable CLASSPATH

then compile your .java file where you have and copy the .class file to the tomcat/webapp/(your directory if any)/WEB-INF/classes
then you include your servlet in WEB-INF/web.xml
open a browser and http://localhost:8080/(your directory if any)/Servlet name

Hope this is what you have asked for
AsifAimen Iqbal
Greenhorn

Joined: Mar 06, 2009
Posts: 9
Venkat,Tim & Greeshma thanks alot for the help.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Go through HFSJ.It's all written there.
AsifAimen Iqbal
Greenhorn

Joined: Mar 06, 2009
Posts: 9
Hi,
Well I did not get HFJS but regarding my earlier issue i did set CLASSSPATH and path correctly but when i try to compile it the following errors are coming.

C:\Users\Guest\Desktop>javac BeerSelect.java
BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
BeerSelect.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
BeerSelect.java:5: cannot find symbol
symbol : class io
location: package java
import java.io;
^
BeerSelect.java:7: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet {
^
BeerSelect.java:8: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)
^
BeerSelect.java:8: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)
^
BeerSelect.java:9: cannot find symbol
symbol : class IOException
location: class com.example.web.BeerSelect
throws IOException,ServletException {
^
BeerSelect.java:9: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
throws IOException,ServletException {
^
BeerSelect.java:11: cannot find symbol
symbol : class PrintWriter
location: class com.example.web.BeerSelect
PrintWriter out=response.getWriter();
^
9 errors
Hanuma Deepak Muvvala
Ranch Hand

Joined: Nov 20, 2005
Posts: 158
It seems that classpath is not set correctly, it is better to use any IDE like Eclipse.

Thanks,
Deepak.
AsifAimen Iqbal
Greenhorn

Joined: Mar 06, 2009
Posts: 9
Thanks Deepak,
But I want to start with the Basic and i m stuck here dont know what to do.I did set CLASSPATH and path correctly but i have placed my servlet in package is that the reason for the error!!!
 
GeeCON Prague 2014
 
subject: How to Deploy servlet using Tomcat 5