• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

very tedious question!

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the problem which I had written above related to browser..I'm using IE version 6.0
Do I need to make some changes in the mime types of the browser to display files..
thanx in advance!
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic