admin管理员组文章数量:1332896
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 mented. 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?
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 mented. 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?
Share Improve this question edited Jan 3, 2013 at 20:50 asked Jan 3, 2013 at 20:39 user1820275user1820275 1- 1 You cannot use sendRedirect(), what that is used for is the client asked for A but the server says you really want B. What you are doing is returning A but in such a way that it loads B for that you need to use javascript or a meta tag. – BevynQ Commented Jan 3, 2013 at 20:43
3 Answers
Reset to default 1You can use JavaScript do the trick. For example:
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>");
}
Instead of redirecting a page using sendRedirect
, Use
window.location.href = 'pageB.jsp'
You can call a jsp page instead of servlet and canuse a jQuery plugin thickbox
http://thickbox/
本文标签: javaHow can i open a window popup in Servlet and then Redirect a PageStack Overflow
版权声明:本文标题:java - How can i open a window popup in Servlet and then Redirect a Page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742313295a2451311.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论