1

I am using an AJAX request to redirect a user to another page inside my web servlet. When the page is redirected, I can see through the log that the method doGet or doPost was load but the PrintWriter does not create the html tag.

public void doPost(HttpServletRequest request,
               HttpServletResponse response) throws IOException{
                performTask(request, response);
               log.info("doPost");
    }

private void performTask(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("TestServlet says hi<br/>");

        out.println("<!DOCTYPE html>\n" + "<html>\n"+"<head><link rel=\"stylesheet\" type=\"text/css\" href=\"formation.css\">");
          out.println("</head>");
          out.println("<body>");
          out.println("<h3>Simple Html</h3>");
          out.println("</body></html>");
        }

I am probably missing something as I this is my first time I actually try to implement a servlet. The message is automatically shown to the user and he does not press any button in order to be redicted. Is this the problem? (Regarding the POST)

Thanks

Mike S.
  • 63
  • 4
  • Ajax response return this page as string format, if you have set `setContentType` otherwise. Using this string content, `var w = window.open(); $(w.document.body).html(response);` – Vish Mar 06 '18 at 18:37

0 Answers0