无法在ubuntu中编译servlet

时间:2010-12-30 10:43:34

标签: java servlets java-ee

我是j2ee的新手。我已经在我的ubuntu 10.04发行版中下载并安装了j2eesdk-1_4_03-linux.bin。然后我尝试将我的第一个servlet编码为:

    import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HowdyServlet extends HttpServlet{
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
                PrintWriter out = response.getWriter();
                response.setContentType("text/html");
                out.println("<html>");
                out.println("<head><title>howdy</title></head>");
                out.println("<body>");
                out.println("<center><h1>Howdy</h1></center>");
                out.println("</body>");
                out.println("</html>");
        }
}

以下是我在安装后设置的环境变量:

1. J2EE_HOME=/home/vinit/SUNWappserver
2. JAVA_HOME=/home/vinit/SUNWappserver/jdk
3. CLASSPATH=/home/vinit/SUNWappserver/lib

现在我尝试使用

编译servlet
javac HowdyServelet.java

但是我遇到了以下错误:

HowdyServlet.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
HowdyServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HowdyServlet.java:5: cannot find symbol
symbol: class HttpServlet
public class HowdyServlet extends HttpServlet{
                                  ^
HowdyServlet.java:6: cannot find symbol
symbol  : class HttpServletRequest
location: class HowdyServlet
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
                          ^
HowdyServlet.java:6: cannot find symbol
symbol  : class HttpServletResponse
location: class HowdyServlet
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
                                                      ^
HowdyServlet.java:6: cannot find symbol
symbol  : class ServletException
location: class HowdyServlet
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
                                                                                                        ^
6 errors

那么如何编译这个servlet。 提前谢谢。

2 个答案:

答案 0 :(得分:2)

设置CLASSPATH=/home/vinit/SUNWappserver/lib没有预期效果;你必须分别在类路径上命名你想要的每个JAR。

答案 1 :(得分:0)

在将servelet更改为servlet

之前,您无法对其进行编译