Servlet Configuration  «Prev  Next»

The JSDK server -Exercise

The JSDK server

Objective:Use the JSDK server to run a sample servlet.
This exercise is worth 5 points.
The exercise is auto-scored, which means that all you have to do to receive credit is to click the Submit button below.

Download Files

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,
  1. The servlet compiles
  2. The Java code above generates the desired output.