aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Need to close PAGE on POST -- please help!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Need to close PAGE on POST -- please help!!!" Watch "Need to close PAGE on POST -- please help!!!" New topic
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!!!
 
Threads others viewed
On click of a Button i eneed to call a JSP Page
Post Production Problem ActiveX JavaScript - Urgent!!
populate the form field with the submitted input
run other jsp without reload current page
Save the form data and go back to main page
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture