• +91 9723535972
  • info@interviewmaterial.com

Servlet Interview Questions and Answers

Question - Explain the steps involved in placing a servlet within a package?

Answer -

The Packages are used to separate the servlets under a directory to eradicate confusion among programmers working simultaneously on creating servlets on the same server. This can be done through the following steps:

  • Sorting of files into different subdirectories by matching the package name to the subdirectory name to organize the packages.
  • After sorting the packages into subdirectories insert the package statement in the class file.
Let us understand through this an example as follows:

  1. import java.io.*;
  2. import javax.servlet.*;
  3. import javax.servlet.http.*;
  4. public class servlet1 extends HttpServlet{
  5.       public void doGet(HttpServletRequest request, HttpServletResponse response)
  6.       throws ServletException, IOException {
  7.              response.setContentType("text/html");
  8.              PrintWriter out = response.getWriter();
  9.              String docType = "n";
  10.              out.println(docType + "n" + "Edurekan" + "n" + "");
  11.       }
  12. }

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners