Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

unable to compile servlet

 
shailendra shrivastava
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Report post to moderator
when i try compling the servlet then i get 6 error saying package
javax.servlet does not exists...


package mypackage;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;




public final class Hello extends HttpServlet {



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

response.setContentType("text/html");
PrintWriter pw = response.getWriter();

pw.println("<html>");
pw.println("<head>");
pw.println("<title>Sample Application Servlet Page</title>");
pw.println("</head>");
pw.println("<body bgcolor=white>");

pw.println("<table border=\"0\">");
pw.println("<tr>");
pw.println("<td>");
pw.println("<img src=\"images/tomcat.gif\">");
pw.println("</td>");
pw.println("<td>");
pw.println("<h1>Sample Application Servlet</h1>");
pw.println("This is the output of a servlet that is part of");
pw.println("the Hello, World application. It displays the");
pw.println("request headers from the request we are currently");
pw.println("processing.");
pw.println("</td>");
pw.println("</tr>");
pw.println("</table>");

pw.println("<table border=\"0\" width=\"100%\">");
Enumeration names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
pw.println("<tr>");
pw.println(" <th align=\"right\">" + name + ":</th>");
pw.println(" <td>" + request.getHeader(name) + "</td>");
pw.println("</tr>");
}
pw.println("</table>");

pw.println("</body>");
pw.println("</html>");

}


}
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
You need to have the servlet JAR file on your classpath when you compile. This JAR is can be found somewhere in your application server path (for example, in Tomcat 5.5 it's in Tomcat\common\lib\servlet-api.jar), or you can download the J2EE SDK from Sun.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
I was going to move this to the Servlet forum, since the question belonged there, but I see it's already posted there. Please do not post questions in multiple forums.

Closing this copy.
 
    Bookmark Topic Watch Topic
  • New Topic