I'm writing the code for the application. My data is in database and I want to retrieve it...
now the file name is in anchor tag and it hits the JSP page when user clicks on this tag...
so the JSP page uses this code
cmd="select f_file from transaction where id='1'";
rs=stmt.executeQuery(cmd);//f_file is the Blob field
if(rs.next())
String fileName=rs.getString("f_name");
download(rs,"f_file","application/a-msdownload",fileName);
and the function is as follows:-
public void download(ResultSet rs,String columnName,String contentType,String destFileName)
{
byte b[]=rs.getBytes(columnName);
if(contentType==null)
response.setContentType("appliation/x-msdownload");
else
response.setContentType(contentType);
response.setContentLength(b.length);
if(destFileName==null)
response.setHeader("Content-Disposition","attachment;");
else
response.setHeader("Content-Disposition","attachment;fileName=".concat(String.valueOf("destFileName)));
response.getOutputStream().write(b,0,b.length);
}
*********************************
Now the problem is that earlier it was executing with giving opening the file with garbage data in first few words of firs line....
Now today when I tried it didn't worked at all..and instead for .doc or .txt files...it says that file doesn't exist and if I want to create new file...so there is no content at all.
when I open html page it gives the excpetion that the getOutputStream() method is already defined...
so please tell me what to do? I mean what is the problem and what content type to set for different files?
any kind of help will be greatly appreciated, as I'm close to finish this project, but this is the only hassle...
thanx a lot...