Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File download popup  RSS feed

 
ashwini kallur
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a button on a JSP Page , Onclick of it calls an XML file(Which creates file on server side). The file which is created by this XML file should come as popup to the user to save/download.Here the popup comes before file download..Please point me in right direction
<html>
<head>
</head>
<body>
<input type=button onClick="parent.location='http://../../ReportForDownload.xml'" value='ECR Report'>
<%
File contextDir = new File("C:\\ABC.xlsx");
ServletOutputStream myOut=response.getOutputStream();
try{
response.setHeader("Content-disposition",
"attachment;filename=" + contextDir.getName());
int len = 0;
int readBytes = 0;
FileInputStream is = new FileInputStream(contextDir);
while((readBytes = is.read( )) != -1)
{
myOut.write(readBytes);
}
is.close();
}finally{
myOut.flush();
myOut.close();
}
%>
</body>
</html>
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36441
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwini,
Welcome to CodeRanch!

I see two concepts on this page - a button to download and creation of a file. (They don't seem to be the same file either.)

These should be two separate things. Have your JSP just be the button for the user to click. It should then redirect to a servlet (not a JSP - it is bad practice to have Java code in a JSP.) The servlet would return the bytes of the XML file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!