2 Replies Latest reply: Jul 24, 2012 11:28 AM by hh*394375*91 RSS

    Why did servlet print as plain text instead of converting it to HTML?

    hh*394375*91
      I learning java an created the following servlet. The only problem is it printed to the browser as text instead of html..

      It literally printed like this.
      <html>
      <HEAD><TITLE>Hellow World</TITLE></HEAD>
      <body>
      This STUFF IS WORKING!!!!!!!!!!!!!!!!!!
      </body></html>

      Why???

      This is the servlet I created.
      package sample;

      import java.io.*;
      import javax.servlet.*;
      import javax.servlet.http.*;

      public class HelloWorld extends HttpServlet {

      public void doGet(HttpServletRequest request,
      HttpServletResponse res)
      throws ServletException, IOException {
      res.setContentType("text/plain");
      PrintWriter out = res.getWriter();
      out.println("<html>");
      out.println("<HEAD><TITLE>Hellow World</TITLE></HEAD>");
      out.println("<body>");
      out.println("This SHIT IS WORKING!!!!!!!!!!!!!!!!!!");
      out.println("</body></html>");
      }
      }


      Thanks Howard