Error: package javax.servlet does not exist import javax.servlet. *

1

I've created the directories correctly, copied the code and now does not compile and returns this error. I'm compiling the terminal using javac.

link

package com.example.web;

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

    public class BeerSelect  extends HttpServlet {

        public void doPost ( HttpServletRequest request,
            HttpServletResponse response )
            throws IOException , ServletException{

            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
                out.println("Beer Selection Advice <br>");
            String c = request.getParameter("color");
                out.println("<br> Got beer color " + c);

        }
    }

Stacktrace in the terminal:

src/com/example/web/BeerSelect.java:3: error: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/web/BeerSelect.java:4: error: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
src/com/example/web/BeerSelect.java:7: error: cannot find symbol
    public class BeerSelect  extends HttpServlet {
                                     ^
  symbol: class HttpServlet
src/com/example/web/BeerSelect.java:9: error: cannot find symbol
        public void doPost ( HttpServletRequest request,
                             ^
  symbol:   class HttpServletRequest
  location: class BeerSelect
src/com/example/web/BeerSelect.java:10: error: cannot find symbol
            HttpServletResponse response )
            ^
  symbol:   class HttpServletResponse
  location: class BeerSelect
src/com/example/web/BeerSelect.java:11: error: cannot find symbol
            throws IOException , ServletException{
                                 ^
  symbol:   class ServletException
  location: class BeerSelect
6 errors
    
asked by anonymous 29.12.2014 / 19:54

1 answer

0

The displayed error occurs because the compiler can not find and therefore can not import javax.servlet because that jar is inside the web server. To compile properly via the command line you need to specify the path to the jar:

javac -classpath .:/caminho/para/o/jar/javax.servlet.jar com/example/web/BeerSelect.java

Source: link

    
30.12.2014 / 23:50