• +91 9723535972
  • info@interviewmaterial.com

Servlet Interview Questions and Answers

Question -
How can you use a servlet to generate a plain text instead of HTML?



Answer -

A servlet basically generates HTML. We can set the content-type response header by any of the methods. The example for producing text message EDUREKA using the HTML code inside the servlets.

  1. import java.io.*;
  2. import javax.servlet.*;
  3. import javax.servlet.http.*;
  4. public class EDUREKA 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.               out.println("n" +"n" +"EDUREKAn" + "n" + "

    HAPPY LEARNING

      n" + "");
  10.        }
  11. }

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners