0

I am trying to display a result in pop-up and then redirect to jsp page.

I have used bellow code ,which is not displaying pop up and it is redirecting to jsp page.

out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet NewServlet</title>");            
        out.println("</head>");
        out.println("<body onLoad=\"myFunction();\">");
        out.println("<script>");
        out.println("function myFunction(){");
        out.println("alert(\""+splitVal[4]+"\")");
        out.println("}");
        out.println("</script>");
        out.println("</body>");
        out.println("</html>");
      response.sendRedirect("NewFile1.jsp");

Both are not working at once. Individually I am able to display pop up and redirect to jsp page and in the above code pop-up is not displaying, But it is not working together. Please help me. Thanks.

itwasntme
  • 1,442
  • 4
  • 21
  • 28
Learn
  • 1
  • 1
  • 4
  • it's beacuse your servlet goes with your instructions - redirects to the NewFile1.jsp in the very end. Single servlet call wont display two different pages, and for more, how it would know that user actually saw pop-up before redirection? Use `js` only for such matters. – itwasntme Aug 08 '15 at 16:29
  • yes.I have added the response.sendRedirect("NewFile1.jsp"); in get method of servlet.even though it is not working. – Learn Aug 11 '15 at 09:20
  • didnt get my comment at all, huh? Anyway, App container executes your servlet line by line, it starts to preparing pop-up related output, but when it comes to an end it sees that it needs to redirect to other `jsp` page - and this is what it does. – itwasntme Aug 11 '15 at 09:24
  • 1
    Remove `.sendRedirect()` from servlet then add some timer to your `JavaScript` and after it exceeds use `window.location.replace("...")` method in `js` to redirect to `NewFile1.jsp` - the `.jsp` page need to be accessible in a static way, if it isn't then change some control in your servlet for when it gets proper parameters it won't display pop-up but instead it will redirect to `NewFile1.jsp` also check out this: http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-using-jquery – itwasntme Aug 11 '15 at 09:30

0 Answers0