1
I created the directories correctly, copied the code and now does not compile and returns this error. I am compiling by the terminal using javac.
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
Are you sure that q Servlet-api is on the classpath of your application? It seems not.
– Juliano Alves
I don’t know.. how do I know? I set up Classpath in the terminal pointing to the Servlet jar
– Fábio Miranda
Post the commands you use in the terminal to compile.
– Victor Stafusa