Package javax.servlet does not exist

Tenho o seguinte codigo:

[color=“blue”]
import javax.servlet.;
import javax.servlet.http.
;
import java.io.;
import java.util.
;

public class TestingServlet extends HttpServlet{
public static void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

PrinterWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Testing</title>");
out.println("</head>");
out.println("<body>");
out.println("<center>Welcome to the first Servlet Testing Center</center>");
out.println("</body>");
out.println("</html>");
}

}
[/color]

Quando tento compilar ele da o seguinte erro:

[color=“red”]C:\tomcat-5.5.4\jakarta-tomcat-5.5.4\webapps\myApp\WEB-INF\classes\TestingServlet.java:1: package javax.servlet does not exist
import javax.servlet.;
^
C:\tomcat-5.5.4\jakarta-tomcat-5.5.4\webapps\myApp\WEB-INF\classes\TestingServlet.java:2: package javax.servlet.http does not exist
import javax.servlet.http.
;
^
C:\tomcat-5.5.4\jakarta-tomcat-5.5.4\webapps\myApp\WEB-INF\classes\TestingServlet.java:6: cannot find symbol
symbol: class HttpServlet
public class TestingServlet extends HttpServlet{
^
C:\tomcat-5.5.4\jakarta-tomcat-5.5.4\webapps\myApp\WEB-INF\classes\TestingServlet.java:7: cannot find symbol
symbol : class HttpServletRequest
location: class TestingServlet
public static void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
^
C:\tomcat-5.5.4\jakarta-tomcat-5.5.4\webapps\myApp\WEB-INF\classes\TestingServlet.java:7: cannot find symbol
symbol : class HttpServletResponse
location: class TestingServlet
public static void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
^
C:\tomcat-5.5.4\jakarta-tomcat-5.5.4\webapps\myApp\WEB-INF\classes\TestingServlet.java:7: cannot find symbol
symbol : class ServletException
location: class TestingServlet
public static void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
^
C:\tomcat-5.5.4\jakarta-tomcat-5.5.4\webapps\myApp\WEB-INF\classes\TestingServlet.java:9: cannot find symbol
symbol : class PrinterWriter
location: class TestingServlet
PrinterWriter out = response.getWriter();
^
7 errors[/color]

Alguém poderia me dar uma ajuda, este é o primeiro exemplo do livro do BUDI

vc precisa colocar o pacote javax.servlet no seu classpath…

vc está usando alguma IDE ?

vc pode baixar o pacote javax.servlet nesse link:

https://jsecom15k.sun.com/ECom/EComActionServlet/LegalPage:~:com.sun.sunit.sdlc.content.LegalWebPageInfo;jsessionid=4665A5310137A12D7D38E47F0FB6BB1E;jsessionid=4665A5310137A12D7D38E47F0FB6BB1E

você verá o seguinte texto: Click below to download… logo abaiixo está o link para baixar o arquivo zipado!

se for JCreator é só colocar esse pacote no jdk profiles do JCreator:

MENU CONFIGURE >> OPTIONS >> opcao JDK Profiles

ou vc pode pegar so seu Tomcat mesmo…
copie o arquivo ‘servlet-api.jar’ da pasta “U:\Tomcat 5.0\common\lib” para a pasta “U:\J2SDK\jre\lib\ext”, que funciona…

:wink:

tu tens q por o pacote no classpath antes

algo como -classpath $CATALINA_HOME/common/lib/servlet.jar

Apartir do TOMCAT 5, o arquivo chama Servlet-api.Jar, fica dentro do TOMCAT_5/common/lib, é só você colocar no seu classpath