| Author |
Need to close PAGE on POST -- please help!!!
|
Mike London
Ranch Hand
Joined: Jul 12, 2002
Posts: 867
|
|
I have a JSP page that POSTS back to itself, the default. Then, if a pararameter was received in the POST, I run some JSP code, but then I want to be able to CLOSE THE PAGE. I can't figure out how to get the combination of POSTing back to the same page and closing the window (page) to work. If I try something like on-Click = "window.close();" in the Submit button, the Submit never happens. If I try to call a Javascript function from the submit button, I'm not sure if I can run the server code. The bottom line is that I need to run some JSP code after the POST back to the same page and then close the PAGE. Can this be done??? Please help!!! Thanks in advance. -- Mike
|
 |
Yuriy Fuksenko
Ranch Hand
Joined: Feb 02, 2001
Posts: 411
|
|
put into jsp: <% if(request.getAttribute("needtoclose") != null){ %> <script>self.close()</script> <% return; } %> After that, if you reached that jsp, and request has attribute "needtoclose" set to anything, page will be closed. Note, that you have to use RequestDispatcher.forward to reach this page, not a sendRedirect.
|
 |
Yuriy Fuksenko
Ranch Hand
Joined: Feb 02, 2001
Posts: 411
|
|
|
By the way, I am assuming this is a popup window, not the main one.
|
 |
Mike London
Ranch Hand
Joined: Jul 12, 2002
Posts: 867
|
|
Thanks, but this code doesn't work. In fact, I even tried this in the JSP: session.setAttribute("needtoclose", "yes"); // see if we need to close... if(request.getAttribute("needtoclose") != null) { %> <script>self.close()</script> <% return; } else { out.println("Didn't get parameter"); } On the post it says: "Didn't get parameter". Any ideas why? Thanks again. -- Mike
|
 |
Mike London
Ranch Hand
Joined: Jul 12, 2002
Posts: 867
|
|
Thanks, but this code doesn't work. In fact, I even tried this in the JSP: session.setAttribute("needtoclose", "yes"); // see if we need to close... if(request.getAttribute("needtoclose") != null) { %> <script>self.close()</script> <% return; } else { out.println("Didn't get parameter"); } WHen I post it prints: "Didn't get parameter". Any ideas why? Thanks again. -- Mike
|
 |
Mike London
Ranch Hand
Joined: Jul 12, 2002
Posts: 867
|
|
Oops, I should have done session.getAttribute and session.setAttribute. However, this code still doesn't work even with that correction. Look forward to anyone's reply! Thanks. -- Mike
|
 |
Mike London
Ranch Hand
Joined: Jul 12, 2002
Posts: 867
|
|
Sorry for all the POSTS here (pun intended).. The following code embedded in my JSP correctly closed the page when needed: <script>window.close</script> Thanks for all the ideas and help! -- Mike
|
 |
 |
|
|
subject: Need to close PAGE on POST -- please help!!!
|
|
|