• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem working on Servlets..plz help..

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was trying to compile a simle servlet by giving the command
javac -classpath c:\Tomcat5.0\common\lib\servlet-api.jar -d classes c:\pr1\src\chservlet.java

why am i getting the error..
package..javax.servlet doesnt exist..
plz help me out..
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jaismeen,

What it means is that the Servlet API classes are not being found on your classpath. May be there is some spelling mistake in the classpath you specify.
or you may want to copy servlet-api.jar (make sure it contains the 'servlet' classes, just in case) to a specially created directory for jars, such as c:\jars, and set the classpath to that location.

cheers
Sonny
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jaismeen,

Your problem is pertaining to the class path not being set to the place where the servlet.jar file is located.

In your system, go to

1. CATALINA_HOME/commons/lib directory.

2. Check whether the servlet.jar file is existing.

3. If it is there, set the Environment variable
classpath = %CATALINA_HOME%\commons\lib\servlet.jar;
4. Restart your Tomcat... It should work fine.

If you don't have, just load the servlet.jar down and place it in ur lib directory. That should work. In case of troubles, you know where to come.

Cheers,
Swamy
 
Sonu Kaur
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry guys..for starting each time new thread..just registered myself to the site yesterday after facing this problem..so cudnt get familiar with its working..

i have given the commands as follows..

set classpath=c:\Tomcat5.0\common\lib\servlet-api.jar,%classpath%
set path=c:\jsdk1.4\bin;%path%
javac c:\pr1\src\chservlet.java

getting the following errors

C:\>javac c:\pr1\src\chservlet.java
c:\pr1\src\chservlet.java:1: package javax.servlet does not exist
import javax.servlet.*;
^
c:\pr1\src\chservlet.java:2: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
c:\pr1\src\chservlet.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class chservlet
public class chservlet extends HttpServlet
^
c:\pr1\src\chservlet.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class chservlet
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOExcep
tion
^
c:\pr1\src\chservlet.java:7: cannot resolve symbol
symbol : class HttpServletResponse
location: class chservlet
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOExcep
tion
^
5 errors

was just wondering.ihave windows xp..so does it effect in anyway(it shud not)
and if name of the servlet is given wrong then it shudnt give these set of errors..it shud give kind a"cudnt find the file name"
and i have checked the classpath..servlet-api.jar is present and is in this location
c:\Tomcat 5.0\common\lib

and i had tried giving the command
jar -tvf servlet-api.jar..
it gives the list of classes..which shows..its present in the directory

jdk is present in c:\jsdk1.4

location of servlet is c:\pr1\src\chservlet.java

servlet code is as follows

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

public class chservlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException
{
PrintWriter out =res.getWriter();
java.util.Date today= new java.util.Date();
out.println("<html>"+
"<body>"+
"<h1 align=center>HF\'s Chapter1 Servlet<h1>"
+"<br>"+today+"</body>"+"</html>");
}
}

even i tried copynig servlet-api.jar in the same directory as the servlet and compiling it..
it gives the same set of errors


am just wondering what cud be the problem.sure..must b very smal..but i m not progressing much

regards
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to have semicolons separating the folders/jars in your classpath. You currently have a comma.
set classpath=c:\Tomcat5.0\common\lib\servlet-api.jar;%classpath%

Also, is there a space between Tomcat and 5.0? Is it Tomcat5.0 or Tomcat 5.0?

Small things like these matter.
Sheldon Fernandes
[ October 01, 2004: Message edited by: Sheldon Fernandes ]
 
Sonu Kaur
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnx
i got the servlet compiled..very true..
..the very small thing which was bothering..was a space between Tomcat 5.0
regards
 
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic