• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unwanted browser window

 
stuart armstrong
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the following code inside a Servlet to allow users to click on a button to download (open/save) an XML file - This works fine. However when the user clicks the download button a new browser window is opened. Is there anyway using Servlets to close this window? I thought about changing the content type then writing out some JavaScript to close the browser, however I don�t think this is possible.

Any help would be greatly appreciated

response.setContentType( "text/xml" );
response.setHeader( "Content Disposition", "attachment;filename=downloadXML.xml" );

//send the data
response.getOutputStream().println( xmlDataString );
response.getOutputStream().flush();
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the HTML for the button that the user clicks?
 
stuart armstrong
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<a href='/app/downloadReports.do?ctrl=publishedReportList&action=DownloadXml¶m=0' target='_blank' title='Download Report XML'>
<img vspace='0' align='absmiddle' border='0' src='images/auditlogicon/contract.gif'>
</a>
 
Darren Edwards
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get rid of target="_blank", that is what's forcing a new window to open.
 
stuart armstrong
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I don't open a new window how would I get the servlet to redirect to the screen which has the button that the user has just clicked on?
 
Darren Edwards
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you have a few options;

download page being the jsp/servlet that generates the download
source page being the page with the download link/button on

- add a link on the download page to return to the source page
- have the source page and download page as the same page (when you click the download link you remain on the same page)

IMO, what you shouldn't be doing is trying to control the user's browser by closing a window.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic