Use content-disposition to provide a save-as popup on browser

一月 21, 2008 @ 8:17 下午 | 发表在 J2EE, Java | 留下评论

Often times you need to prompt user a save-as dialog box with a default file name. This can be done through the content-disposition HTTP header. A sample java code snippet follows:

// Set the headers.
res.setContentType(“application/x-download”);
res.setHeader(“Content-Disposition”, “attachment; filename=” + filename);

// Send the file.
OutputStream out = res.getOutputStream(  );

Advertisements

发表评论 »

RSS feed for comments on this post. TrackBack URI

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

通过访问 WordPress.com 创建免费网站或博客.
Entries评论 feeds.

%d 博主赞过: