Hi all,
I am new to this programing.
can any one help me to proceed with my coding - to download a file from a remote location.
i have writtent he following code:
[ jsp ]
<body>
Click <a href="/filefunctions/DownLoadServlet?file=C:/uploads/test1.txt">
here</a> to download text1.txt
</body>
[ servlet ] :
final ServletOutputStream out = response.getOutputStream();
response.setContentType("application/octet-stream");
//Get the URL
// Get the resource to view
String file = request.getPathInfo();
System.out.println("file "+file);
if (file == null) {
out.println("Extra path info was null; should be a resource to view");
return;
}
// Convert the resource to a URL
URL url = getServletContext().getResource(file);
if (url == null) { // some servers return null if not found
out.println("Resource " + file + " not found");
return;
}
// Serve the file
InputStream in = url.openStream();
byte[] buf = new byte[4 * 1024]; // 4K buffer
int bytesRead;
while ((bytesRead = in.read(buf)) != -1) {
out.write(buf, 0, bytesRead);
}
}
but it is printing "Extra path info was null; should be a resource to view"
can any one help how to overcome this , and download the file from remote loaction successfully..
please reply as early as possible , i have very less time to complete the coding
thanks in advance
/laksh