Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deploying Servlets on tomcat

 
Suni Kr
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you deploy servlets on tomcat(installed on windows)?what is the command?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. All that you need to know about how to deploy servlets is in documentation that comes with your Tomcat download. Once you have tomcat running, you can read it from your own system.
2. The ranch actually has a Tomcat specific section.
Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Tomcat forum.
 
Suni Kr
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam unable to compile my servlet on tomcat.
When I use the javac command it says,

"'javac' is not recognized as an internal or external command,
operable program or batch file."

I have set JAVA_HOME = C:\java-2sdk1.4.2_05
Please tell me what is the problem.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suni,

Did you set the PATH? javac can be found under the bin directory.

PATH = C:\java-2sdk1.4.2_05\bin

You can check the value of PATH with the command "echo %PATH%".

Joyce
[ October 15, 2004: Message edited by: Joyce Lee ]
 
Suni Kr
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joyce ,
I have set the variable PATH = C:\java-2sdk1.4.2_05\bin but it doesn't show it when I say 'echo %PATH%'.
How can I set it from the DOS window.(there are already some values to the PATH variable so how can I add to it a new value.)

thank you,
suni
 
Nandini Sriram
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suni,

To set your Path, you can follow this:

1.Right click on 'My Computer' (from your desktop)
2. Select 'Properties'
3. Select the 'advanced' tab
4. Press the 'Environment Variables' button under System variables scroll till you see 'Path'
5. Select 'Path'
6. Press the 'edit' button - at the very end add, C:\java-2sdk1.4.2_05\bin;

If you want to do it from the DOS prompt,
>set PATH = %PATH%;C:\java-2sdk1.4.2_05\bin
but then when you open a new DOS window, you have to again 'set' this path.

Regards,
Nandini
 
Suni Kr
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank for the reply Nandini.I did all that and now my variables are set fine but when I compile the servlet using

"javac -classpath C:\ApacheSoftwareFoundation\Tomcat5.0\common\lib\servlet-api.jar:classes:. -d src\com\example\web\BeerSelect.java"

I get the following error messages:

"src\com\example\web\BeerSelect.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
src\com\example\web\BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.http;
^
src\com\example\web\BeerSelect.java:4: cannot resolve symbol
symbol : class io
location: package java
import java.io;
^
src\com\example\web\BeerSelect.java:6: cannot resolve symbol
symbol : class HttpServlet
location: class com.example.web.BeerSelect
class BeerSelect extends HttpServlet{
^
src\com\example\web\BeerSelect.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{"

And some more similar errors. Please advise me what to do and also tell me what does "...servlet-api.jar:classes:." mean in the above command.
thank you,
Suni.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

Assuming you're now in .\example\web directory.

javac -classpath C:\ApacheSoftwareFoundation\Tomcat5.0\common\lib\servlet-api.jar BeerSelect.java


Alternatively, you can set CLASSPATH in Environment Variable just like PATH so that you can compile without the -classpath option. For more info on setting the tomcat, you can check out CoreServlet: Tomcat.

SET CLASSPATH=%CLASSPATH%;.;C:\ApacheSoftwareFoundation\Tomcat5.0\common\lib\servlet-api.jar;


servlet-api.jar consists all the servlet api classes such as HttpServlet, HttpServletRequest. You can view the content of the jar file using "jar tf servlet-api.jar".

For the import, the ending must be either an asterisk or a class name. In JDK 1.5 (tiger), it can end with a static member.

import javax.servlet.http.*;
import java.io.*;


Joyce
[ October 16, 2004: Message edited by: Joyce Lee ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you get away from the simplest servlet examples, the classpath problems get weirder and weirder. Then you should consider building projects with ANT - a considerable learning curve but worth it.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic