• 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

servlet class not compiling. Classpath problem?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am unable to compile a servlet class example given in my J2EE book. I am using j2se 1.4.0 and j2ee1.3.1 on win xp. I have set the following environment variables -
1. J2EE_HOME : C:\j2sdkee1.3.1
2. JAVA_HOME : c:\j2sdk1.4.0_01
3. PATH : c:\j2sdk1.4.0_01\bin;c:\j2sdkee1.3.1\bin;c:\j2sdkee1.3.1\jakarta-ant-1.3\bin;c:\borland\bcc55\bin;C:\FSC\PCOBOL32;%SystemRoot%\system32;%SystemRoot%;C:\FSC\PowerFORM;C:\FSC\PSORTOCX;C:\FSC\COBOL97;%SystemRoot%\System32\Wbem;.;
The error message i am getting is -
C:\j2sdkee1.3.1>javac BankServlet.java
BankServlet.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
BankServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
BankServlet.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class BankServlet
public class BankServlet extends HttpServlet
^
BankServlet.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class BankServlet
public void doPost( HttpServletRequest req, HttpServletResponse res ) throws
ServletException, IOException
^
BankServlet.java:7: cannot resolve symbol
symbol : class HttpServletResponse
location: class BankServlet
public void doPost( HttpServletRequest req, HttpServletResponse res ) throws
ServletException, IOException
^
BankServlet.java:7: cannot resolve symbol
symbol : class ServletException
location: class BankServlet
public void doPost( HttpServletRequest req, HttpServletResponse res ) throws
ServletException, IOException
^
6 errors
C:\j2sdkee1.3.1>
Is it because i have no classpath setting? If so, what should i set it to?
Thanks for any help.
- Rahul
P.S. The code of my servlet class is -
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class hitcountServlet extends HttpServlet
{
static int count;
public void init( ServletConfig config ) throws ServletException
{
super.init( config );
}
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
count++;
out.println("<html>");
out.println("<head><title>BasicServlet</title></head>");
out.println("<body>");
out.println("You are user number " + String.valueOf(count) + " visiting our web site" + "\n" );
out.println("</body></html>");
}
public String getServletInfo()
{
return "BasicServlet Information";
}
}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler is not finding servlet.jar.
In my opinion, it is worth the trouble of the learning curve to learn ANT and use it for all but the simplest projects. You can stop worrying about your environment CLASSPATH and set a classpath for the compiler that is specific to the project.
Here is an example from one of my servlet projects build.xml

That definition gets used when calling the compiler like this:

Having that specific control on a per project basis makes it easier to cope with all the different versions of various libraries.
Bill
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had come across the same problem once. You should set the path to servlet.jar, which comes with your web server, like Apache Tomcat. Refer to your web server documentation for details on how to set this path. By the way I don't think J2EE_HOME helps anything.
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can either set the classpath as one your system environment variables or you can set it at
compile time:


cj
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correction: change that
binto a lib like so ..

and you should be okay. Sorry.
Craig
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I faced the same problem when I first compiled my servlets.
I copied the servler.jar to
c:\j2sdk1.4.0_01\jre\lib\ext and it solved my problem.
 
Rahul Dasgupta
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
Thanks for trying to help me. I have set a claspath as .;c:\j2sdkee1.3.1\lib\j2ee.jar in the environment variables and everything seems to be fine now.
- Rahul
 
My honeysuckle is blooming this year! Now to fertilize 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