Hi the gurus here. I'm caught in very helpless position and I think that only gr8 persons like u can solve this problem..here it goes
I'm making an application using jsp and apache-tomcat as the server. Now I want to download the file from the database server. For this I'm using the following code..
cmd="select con_type,f_name from transaction where id='1';
rs=stmt.executeQuery(cmd);
if(rs.next())
{
String contentType=rs.getString("con_type");//con_type is the contenttyp
String fileName=rs.getString("f_name");
}
cmd="select * from transaction where id='1';
rs=stmt.executeQuery(cmd);
beanId.downloadField((rs,"f_file",contentType,fileName);
and the function which is in a bean class is as follows:--
public void downloadField(ResultSet rs, String columnName, String contentType, String destFileName)
throws SQLException, IOException, ServletException
{
if(rs == null)
throw new IllegalArgumentException("The RecordSet cannot be null (1045).");
if(columnName == null)
throw new IllegalArgumentException("The columnName cannot be null (1050).");
if(columnName.length() == 0)
throw new IllegalArgumentException("The columnName cannot be empty (1055).");
byte b[] = rs.getBytes(columnName);
if(contentType == null)
m_response.setContentType("application/x-msdownload");
else
if(contentType.length() == 0)
m_response.setContentType("application/x-msdownload");
else
m_response.setContentType(contentType);
m_response.setContentLength(b.length);
if(destFileName == null)
m_response.setHeader("Content-Disposition", "attachment;");
else
if(destFileName.length() == 0)
m_response.setHeader("Content-Disposition", "attachment;");
else
m_response.setHeader("Content-Disposition", "attachment; filename=".concat(String.valueOf(destFileName)));
m_response.getOutputStream().write(b, 0, b.length);
}
so now when I download the file then it gives me pop-up box with the default name as "Download.jsp" whereas I haven't specified any name. and if I click to open the file...then it opens word document and with alert box saying "C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\Content\45MFWD2F\Download[1].jsp
Cannot find this file.
Please verify that correct path and file Name are given."
and if I open .html file then it says that nullpointer exception
if I open .class file then it says "IllegalStateException getOutputStream() has already been called for this response!"
any help will be greatly appreciated.
thanx