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.
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class EDUREKA extends HttpServlet{
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException{
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- out.println("n" +"n" +"EDUREKAn" + "n" + "
HAPPY LEARNING
n" + ""); - }
- }