This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes very tedious question! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "very tedious question!" Watch "very tedious question!" New topic
Author

very tedious question!

honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
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

Joined: Apr 26, 2002
Posts: 44
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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: very tedious question!
 
Similar Threads
Upload Download File
how to deal with the garbage data in JSP?
File download with servlets
Problem with downloading files
How to download csv file