GeeCON Prague 2014*
The moose likes Servlets and the fly likes servlet class not compiling. Classpath problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet class not compiling. Classpath problem?" Watch "servlet class not compiling. Classpath problem?" New topic
Author

servlet class not compiling. Classpath problem?

Rahul Dasgupta
Greenhorn

Joined: Jun 01, 2002
Posts: 20
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";
}
}
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
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
shaohuawang
Greenhorn

Joined: Sep 08, 2002
Posts: 1
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.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
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

Joined: Mar 19, 2002
Posts: 405
Correction: change that
binto a lib like so ..

and you should be okay. Sorry.
Craig
Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
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

Joined: Jun 01, 2002
Posts: 20
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
 
 
subject: servlet class not compiling. Classpath problem?