如何在Servlet中打开窗口弹出窗口,然后重定向页面 [英] How can i open a window popup in Servlet and then Redirect a Page

查看:756
本文介绍了如何在Servlet中打开窗口弹出窗口,然后重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在调用servlet时打开一个弹出窗口,然后想要将servlet重定向到某个 .jsp 页面。

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

这就是我所做的:

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");
    }

此代码仅在响应时弹出窗口。 sendRedirect(error.jsp); 不存在或已注释。目前使用此代码,它不弹出窗口并直接将此页面重定向到 error.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?

推荐答案

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

window.location.href ='pageB.jsp'

这篇关于如何在Servlet中打开窗口弹出窗口,然后重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆