I have this simple JSP, which flushes a String to the browser as a file (message.txt). The JSP gets opened in a new window when the user clicks a link.
The problem is that after the JSP has run, the browser window won’t close automatically. I’ve tried adding a small javascript to achieve this, but i doesn’t seem to even get run.
How can I close the browser window after the JSP has run?
After the JSP has run, an empty html page with the following source can be seen:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>
The result of this, is that the javascript will be added to the end of the file that get saved. It will not be included in the html page itself. I want the opposite.
Oh I see the problem. I dont’t think you can resolve that easily. You could try to redirect to a page with the window.close() ->
response.sendRedirect(“clospage.html”);
at the very beginning.
I’m setting the plain text content type to make sure the browser downloads the file as plain text.
It looks like that after I’ve closed the outputStream I can’t do any more processing in the JSP. Even if I remove the response.setContentType and response.setHeader methods it still behaves this way.
I’m starting to think that there’s no way around this…??