1

这是我的代码...一个基本的 servlet 代码。

   //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;
     }
   }

编译它....它抛出 javax.servlet 不存在。当我“ctrl c + ctrl v”编辑它时,类路径和路径是正确的!!!
及其在其他机器上运行,而它在我的显示以下错误响应。我正在使用 Win 7(64 位)......我猜没必要!

  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

我应该怎么办??

4

4 回答 4

1

你应该servlet-api.jar在类路径中。它应该存在于weblogic81\server\lib\目录中。

于 2012-06-28T06:36:27.883 回答
0

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

于 2012-06-28T08:54:15.470 回答
0

您使用的是哪个版本的 weblogic,我认为他们将其移至 moudles/ 文件夹....请查看模块文件夹中的内容,您会发现 javax.servlet_xxxxx.jar

于 2012-06-28T06:41:24.940 回答
0
set classpath = C:\beaB\weblogic81\server\lib\weblogic.jar .

weblogic.jar这将起作用,您可以通过提取来检查 javax 文件夹是否存在于内部weblogic.jar。确保您没有将类路径设置为:-

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

不能有双引号作为"".

于 2015-06-21T13:54:34.847 回答