Wednesday, July 27, 2016

Write a program to display a greeting message in the browser by using HttpServlet.

Aim: Write a program to display a greeting message in the browser by using HttpServlet.

Program:

import javax.servlet.http.*;  
import javax.servlet.*;  
import java.io.*;  
public class DemoServlet extends HttpServlet
{  
public void doGet(HttpServletRequest req,HttpServletResponse res)  
throws ServletException,IOException  
{  
res.setContentType("text/html");//setting the content type  
PrintWriter pw=res.getWriter();//get the stream to write the data  
  
//writing html in the stream  
pw.println("<html><body>");  
pw.println("Welcome to servlet");
pw.println("Hellow all  ");
pw.println("We are from 3-IT ");
pw.println("</body></html>");  
  
pw.close();//closing the stream  
}
}  

Output:

Type url in web browser "http://localhost:9999/servlets/DemoServlet

In the URL 9999 is a port number given in installation process
servlets is a folder created by us under Webapps folder








Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home