Showing posts with label SIMPLE SERVLET PROGRAM. Show all posts
Showing posts with label SIMPLE SERVLET PROGRAM. Show all posts

Friday, May 22, 2015

SIMPLE SERVLET PROGRAM

Aim:
            To write a simple servlet program using HTTP in java.

Algorithm:

  1. Create a servlet program using http.
  2. Set classpath where servlet-api.jar file resides.
  3. Compile the servlet program using javac programname.java
  4. Place the class file …\Tomcat 5.5\webapps\ROOT\WEB-INF\classes\ folder.
  5. modify the web.xml file using your servletClassName.
  6. Invoke the class file using http://localhost:8080/servetClassName from your browser

 Program:

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

public class mailamHome extends HttpServlet
{
  public void doGet(HttpServletRequest request, HttpServletResponse response)
                                   throws ServletException,IOException
  {
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    pw.println("<html>");
    pw.println("<head><title>Hello World</title></title>");
    pw.println("<body>");
    pw.println("<h1>Mailam College of Engineering</h1>");
    pw.println("<h2>An ISO 9001:2000 Certified Institution</h2>");
    pw.println("<h3>Affliated to Anna University</h3>");
    pw.println("</body></html>");
  }
}