• +91 9723535972
  • info@interviewmaterial.com

Servlet Interview Questions and Answers

Question - Write a Hello World Program using Servlets.

Answer -

The code to write a Hello World PRogram using Servlets is as follows:

  1. import java.io.*;
  2. import javax.servlet.*;
  3. import javax.servlet.http.*;
  4.  
  5. public class HelloWorld extends HttpServlet {
  6.       private String message;
  7.       public void init() throws ServletException {
  8.              message = "Hello World";
  9.       }
  10.       public void doGet(HttpServletRequest request, HttpServletResponse response)
  11.       throws ServletException, IOException {
  12.              response.setContentType("text/html");
  13.              PrintWriter out = response.getWriter();
  14.              out.println("

    " + message + "

    "); 
  15.       } 
  16.       public void destroy() { 
  17.       } 
  18. }

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners