This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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/" );
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 =, 0, buff.length)))
bos.write(buff, 0, bytesRead);
Have you checked out Aspose?
subject: save windows?
It's not a secret anymore!