jQuery in Action, 3rd edition
The moose likes HTML, CSS and JavaScript and the fly likes save windows? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "save windows?" Watch "save windows?" New topic

save windows?

Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
how i want to make a popup windows so that when there a link to a file in server...i will pop-up a windows ask whether user want to open or save the file
[ November 29, 2004: Message edited by: Bear Bibeault ]
Anitha Krishnamurthi

Joined: Nov 29, 2004
Posts: 26
call a jsp or servlet on click of the link to the file and write below code on the destination jsp or servlet

String fileName = httpservletrequest.getParameter("filename");
String dirName = httpservletrequest.getParameter("dirname");
int dotIndex = fileName.lastIndexOf(".");
String fileType = fileName.substring(dotIndex+1,fileName.length());
ServletOutputStream out = httpservletresponse.getOutputStream();
if (fileType.trim().equalsIgnoreCase("doc"))
httpservletresponse.setContentType( "application/msword" );
else if (fileType.trim().equalsIgnoreCase("xls"))
httpservletresponse.setContentType( "application/vnd.ms-excel" );
else if (fileType.trim().equalsIgnoreCase("pdf"))
httpservletresponse.setContentType( "application/pdf" );
else if (fileType.trim().equalsIgnoreCase("ppt"))
httpservletresponse.setContentType( "application/ppt" );
httpservletresponse.setContentType( "application/octet-stream" );

httpservletresponse.setHeader("Content-disposition", "attachment; filename=" +fileName);
String filePath = dirName+"/"+fileName;
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filePath));
BufferedOutputStream bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
bos.write(buff, 0, bytesRead);
I agree. Here's the link: http://aspose.com/file-tools
subject: save windows?
It's not a secret anymore!