2012-06-28 49 views
1

这里是我的代码...一个基本的servlet代码后不存在。包的javax.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; 
    } 
    } 

COMPILING it ....它抛出javax.servlet不存在。 类路径和路径是正确的,因为我“ctrl c + ctrl v”编辑它!
及其在其他机器上运行,同时它在我的显示下面的错误响应。 我使用赢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 

我该怎么办?

+0

您可以在javac命令本身中提供类路径,例如'javac -cp C:\ beaB \ weblogic81 \ server \ lib \\ *。jar DemoServlet1.java' –

回答

1

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

的WebLogic版本,您使用的这些
0

,我认为他们把它搬到moudles /文件夹.... 请看到里面的模块文件夹,你会发现javax.servlet_xxxxx.jar

+0

他仍在weblogic 8.1 –

+0

m仍位于weblogic8上。 1 – anurag

0

CLASSPATH中没有的servlet -api.jar。

如果妳使用Eclipse。

右键单击项目 - >构建路径 - >配置构建路径 - >添加外部JAR - >浏览,你有这样的罐子,然后单击确定路径..

如果您正在使用Tomcat服务器,那么你可以发现这个罐子中的Apache Tomcat文件夹的的lib文件夹

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

这工作,你可以检查的javax文件夹里面是否存在weblogic.jar或不能简单地通过提取weblogic.jar。请确保您没有设置类路径为:-

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

不能有双引号""