You should use the following source code displayed here .
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleServlet extends HttpServlet{
public SimpleServlet(){ }
public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException{
ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
httpservletresponse.setContentType("text/html");
servletoutputstream.println("<HEAD><TITLE> SimpleServlet Output </TITLE></HEAD><BODY>");
servletoutputstream.println("<h1> SimpleServlet Output </h1>");
servletoutputstream.println("<P>This is output from SimpleServlet.");
servletoutputstream.println("</BODY>");
servletoutputstream.close();
}
public String getServletInfo(){
return "A simple servlet";
}
}
SimpleServlet.class.
You will need to place it in the following directory:
c:\jsdk2.1\examples\web-inf\servlets.
or place the above source code in the directory of your choice. The important thing to note is,
- The servlet compiles
- The Java code above generates the desired output.