Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to deal with the garbage data in JSP?  RSS feed

 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm making an application in JSP for updating the files to and downloading the files from the database..When I download the files from the database then the file which opens contains some garbage data in the first line and overwrites the original data..
so can anybody tell me the solution for this?
thanx in advance for this..
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"IT Revolution", unfortunately your cool name doesn't comply with our cool official policy on registered names. Both first and last name are required. Please, take a moment and change your publicly displayed name.
 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If anybody can help me with the above given problem...Can u tell me to set the content type of the file to the original content type of file...or to set the content type to default application/x-msdownload...?
thanx...
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Bib Bob", please read this regarding the naming policy.
Dave.
 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had changed the name, now please can I expect my answer to the question..
thanx in advance
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
honey singh wrote: [I][/I]
Surely your SQL query is never asking for a column "f_name", so I guess the fileName variable is being set to null. Try something like:
 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,
thanx for the reply...but I had done this also..and then also it gives me the same error..
thanx in advance!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!