Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable t o compile the servlet .. plz help

 
shailendra shrivastava
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • 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>");

}


}
 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put the servlet-api.jar in your classpath. It's available in tomcat jsp container
 
Pavel Cherkashin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can use j2ee.jar from %J2EE_HOME%\lib directory if you have installed
j2ee-sdk-1.3.1 or other version. But the better way is to use server-native jar library
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic