Aim:
To write a simple servlet program
using HTTP in java.
Algorithm:
- Create
a servlet program using http.
- Set
classpath where servlet-api.jar file resides.
- Compile
the servlet program using javac programname.java
- Place
the class file …\Tomcat 5.5\webapps\ROOT\WEB-INF\classes\ folder.
- modify
the web.xml file using your servletClassName.
- 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>");
}
}