這裏是我的代碼...一個基本的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
我該怎麼辦?
您可以在javac命令本身中提供類路徑,例如'javac -cp C:\ beaB \ weblogic81 \ server \ lib \\ *。jar DemoServlet1.java' –