1
我想从互联网下载文件,我有该文件的网址。所以我写了一个下载的servlet:从gwt网址下载文件
public class DownloadServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
String pathToDownload = request.getParameter("url");
URL url = new URL(pathToDownload);
URLConnection uc = url.openConnection();
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
InputStream is = uc.getInputStream();
response.setContentType(contentType);
// resp.setHeader("Content-Disposition", "attachment; filename*=\"utf-8''" + filename + "");
ServletOutputStream os = response.getOutputStream();
byte[] b = new byte[2048];
int length;
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}
is.close();
os.close();
}
}
在此我想说明的弹出当用户点击文件是否保存或不那么有
resp.setHeader("Content-Disposition", "attachment; filename*=\"utf-8''" + filename + "");
,但我想要的文件名相同作为internate的文件名,所以额外需要在上面的代码片段?