Servlet First Program

Prev Tutorial Next Tutorial

Servlet First Program

Servlet programming is very simple but you need some basic knowledge for example interface, abstract class, exception handling.

Steps to write servlet program

  • Define web directory structure
  • Define .jsp/.html pages
  • Define servlet program, compile into classes folder
  • Define web.xml, into WEB-INF folder
  • Deploy the webroot into web server deployment folder location.
  • Start the server
  • Open web browser and invoke servlet/.html/.jsp.

Write a web applicaton to send hello word as response to client using servlet.

import javax.servlet.*;
public class FirstServlet extends HttpServlet {  
  public void service(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException
   // get request parameter
   // business operation
   String resultvalue="<body bgcolor="cyan" text="red"> <h1> hello word</h1></body>";

   // prepare response
   printWriter out=resp.getWriter();

   // send response





Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain,, @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: WhatsApp no. 8882538826

Yahoo Advertisements