1

I am calling the servlet this way, in the javascript file:

$(document).ready(function () {
    $("#idButton").click(function() {
        var p1 = "hi";
        $.post("myservlet",{p1:p1});
    });
});

The doPost() method code in the servlet is:

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8"); 
        response.sendRedirect("second.jsp");
    }

Debugging with firefox, the call $.post() can be seen. And just after that continuing execution, it also stops debugging within the netbeans in a breakpoint set on the sendRedirect() line.

I even can see that the sendRedirect() is executed, but nothing happens on the firefox browser.

What am I doing wrong? Help will be fully appreciated.

carles
  • 174
  • 1
  • 10
  • as you have use ajax here you need to send response back to it and from there you can redirect to other page using : `window.location.href = "second.jsp";` – Swati Jul 22 '20 at 12:28
  • Thank you very much, Swati. Everything's gone perfect! – carles Jul 22 '20 at 12:39
  • See section "Sending a redirect from servlet" in abovelinked duplicate. – BalusC Jul 22 '20 at 23:12

0 Answers0