3

I want to open a popup window on calling a servlet and then want to redirect servlet to some .jsp page.

This is what i've done:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<script type=\"text/javascript\">");
        out.println("window.open(\"pageA.jsp\")");
        out.println("</script>");
        out.println("</body></html>");
        response.sendRedirect("pageB.jsp");
    }

This code will only popup window when the response.sendRedirect("error.jsp"); is not present or commented. Currently with this code, it is not popping a window and directly redirecting this page to error.jsp

How can i do both of the above things at the same time?

4

3 回答 3

1

您可以使用 JavaScript 来解决问题。例如:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("<html><body>");
    out.println("<script type=\"text/javascript\">");
    out.println("var popwin = window.open(\"pageA.jsp\")");
    out.println("setTimeout(function(){ popwin.close(); window.location.href='pageB.jsp';},5000)");
    out.println("</script>");
    out.println("</body></html>");
}
于 2013-01-03T21:14:53.943 回答
1

而不是使用重定向页面sendRedirect,使用

window.location.href = 'pageB.jsp'

于 2013-01-04T05:05:49.203 回答
-2

你可以调用一个jsp页面而不是servlet,并且可以使用一个jQuery插件thickbox

http://thickbox.net/

于 2013-01-04T04:52:35.047 回答