anurag
anurag

Reputation: 2246

package javax.servlet does not exist even after setting the class path

Here's My code... a basic servlet code.

   //Servlet (interface)
     import javax.servlet.*;
     import java.io.*;
     public class DemoServlet1 implements Servlet
     {
     public void init(ServletConfig config)
     {  }
     public void service (ServletRequest req, ServletResponse res)
                 throws ServletException, IOException
     {
            res.setContentType("text/html");
            PrintWriter out = res.getWriter();
            out.println("<html><body>");
            out.println("WELCOME SERVLET");
            out.println("</body></html>");
     }
     public void destroy()
     {}
     public ServletConfig getServletConfig()
     {
            return null;
     }
     public String getServletInfo()
     {
            return null;
     }
   }

COMPILING it.... it throws javax.servlet does not exist. The classpath and path are correct as I "ctrl c + ctrl v"ed it!!!
and its running on other machines, while its showing the following error response in mine. I am using Win 7 (64bit)... not necessary i guess!!

  G:\2>set path = C:\beaB\jdk141_02\bin

  G:\2>set classpath = %classpath%;C:\beaB\weblogic81\server\lib\weblogic.jar

  G:2>javac DemoServlet1.java 

  DemoServlet1.java:2: package javax.servlet does not exist
  import javax.servlet.*;
  ^
  DemoServlet1.java:4: cannot find symbol
  symbol: class Servlet
  public class DemoServlet1 implements Servlet
                                       ^
  DemoServlet1.java:6: cannot find symbol
  symbol  : class ServletConfig
  location: class DemoServlet1

  public void init(ServletConfig config)
                     ^
  DemoServlet1.java:8: cannot find symbol
  symbol  : class ServletRequest
  location: class DemoServlet1
  public void service (ServletRequest req, ServletResponse res)
                 throws ServletException, IOException

  DemoServlet1.java:8: cannot find symbol
  symbol  : class ServletResponse
  location: class DemoServlet1
  public void service (ServletRequest req, ServletResponse res)throws ServletExcep 
  tion, IOException
                                     ^
  DemoServlet1.java:8: cannot find symbol
  symbol  : class ServletException
  location: class DemoServlet1
  public void service (ServletRequest req, ServletResponse res)throws ServletExcep
  tion, IOException
                                                                ^
  DemoServlet1.java:18: cannot find symbol
  symbol  : class ServletConfig
  location: class DemoServlet1
    public ServletConfig getServletConfig()
           ^
  7 errors

What should I do??

Upvotes: 1

Views: 10157

Answers (4)

RAJAN_PARMAR
RAJAN_PARMAR

Reputation: 139

set classpath = C:\beaB\weblogic81\server\lib\weblogic.jar .

This will work you can check whether javax folder exist inside weblogic.jar or not simply by extracting weblogic.jar. Make sure that you are not setting class path as :-

set classpath = "C:\beaB\weblogic81\server\lib\weblogic.jar" . 

There must not be double quotes as "".

Upvotes: 0

Meenakshi
Meenakshi

Reputation: 468

Your classpath does not have servlet-api.jar.

If u use Eclipse .

Right click the project -> Build path - > configure build path - > Add External jars -> browse the path where you have this jar and click ok..

If you are using tomcat server then you can find this jar in the lib folder of apache tomcat folder

Upvotes: 0

rbhawsar
rbhawsar

Reputation: 813

which version of weblogic are you using, i think they moved it to moudles/ folder .... please see inside the modules folder you will find javax.servlet_xxxxx.jar

Upvotes: 0

Ramesh PVK
Ramesh PVK

Reputation: 15446

You should have servlet-api.jar in the classpath. It should be present in weblogic81\server\lib\ directory.

Upvotes: 1

Related Questions