• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

save windows?

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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" );
}
else
{
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);
}
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic