Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Specify the filename to be used for a file sent by a Servlet
12-14-2010, 08:45 AM
Post: #1
Specify the filename to be used for a file sent by a Servlet
Say that your servlet called ""/servlet/GetFile" send back a file to a client request. That file needs to be saved by the client. If you do nothing, the browser will suggest "GetFile" as the filename.

To specify the correct filename

String filename = "abc.dat" ;
File textFile = new File(filename);
response.setHeader("Content-length",Integer.toString(textFile.length()));
response.setHeader("Content-type","application/octetstream");
response.setHeader("Content-disposition","inline; filename=" + filename );

// open the file and write it in the OutputStream
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:



Send your comments, Suggestions or Queries regarding this site at info@tutorials4u.net

Copyright © 2010 Tutorials4u.net All Rights Reserved