Creating a Simple Servlet - Java Servlet JSP

Java examples for Servlet JSP:Servlet

Description

Creating a Simple Servlet

Demo Code

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class HelloWorld extends HttpServlet
{
     public void doGet(HttpServletRequest request,
          HttpServletResponse response) throws IOException, ServletException{
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          out.println("<html>");
          out.println("<head>");
          out.println("<title>HelloWorld</title>");
          out.println("</head>");
          out.println("<body>");
          out.println("<h1>Hello, World!</h1>");
          out.println("</body>");
          out.println("</html>");
     }//from  w w  w. j ava2s  . c o  m
}

Related Tutorials