• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Download file HELP?

 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all javaranch:
I have a jsp a link to download the file that I get from database as BLOB.
I am using spring, so I have a controller, go get the file from database, and outstream the file and instream, but when I click on the links download, the dialog box not display, to allow me SAVE or OPEN file. Please help
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're telling the browser that the content type is HTML



If you're streaming binary data you should change this to match its mime type.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben:
I do have a method to specify the mimetype for each file type:


 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things.

1.) Your sample code in the first post shows it hard coded.
Which are you using?

2.) The servlet spec provides a method for getting the mime type for all the most common extensions. If you're dealing with uncommon file types, you can add your own to web.xml.
See:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getMimeType(java.lang.String)
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the method to getMimeType to setContentType


Thanks
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben:
Yes i can modified the web.xml, so what do I have to do to include the ServletContext interface that have the getMimeType ? please advise
Thanks
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to map into the web.xml now, but the problem i still ahve is that the dialog does not pop up , is there anything i need to configure or missing in the code? thanks much
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what's happening now?

What type of file are you streaming?
What happens when it's done?
Is it opening in your browser window?
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am streaming a readme.txt file, so it should be setContentType("text/plain")
but not OPen the dialog. It is hitting the servlet, but not doing anything on the browser. (IE Or Firefox).
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh. So, it's not doing anything?
I read your first post to mean that it was making it to the browser but not offering the user the chance to save it.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check your server's logs to see if anything is blowing up?

In this line it looks like you're using the comparison (==) operator where you probably meant to use the assignment (=) operator.

 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben thanks for your reply, and point out,
I did monitor the log, nothing blow up, Not sure why not working
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you fix this?


As it is, len is never being assigned anything.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben:
I did look into the actual line of code, and it is the = sign instead of ==; but still not make any progress, the dialog box still not display

Anything that i possibly miss from the previous posted? I could not figure out, please advise...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jay lai:
Hi Ben:
I did look into the actual line of code, and it is the = sign instead of ==; but still not make any progress, the dialog box still not display

Anything that i possibly miss from the previous posted? I could not figure out, please advise...


That line in your JSP should be blowing up.
<%filename%> is not a valid scriptlet.

To make it a JSP expression, you'll need to add the = symbol.
<%=filename%>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did look into the actual line of code, and it is the = sign instead of ==


Please read the following article carefully.
http://faq.javaranch.com/java/AvoidRedHerrings

Always cut and paste the actual code into Javaranch to avoid wasting time on false bugs in your code. People will quickly tire of helping you if everything they find turns out to be a typo in your posts here but not in the actual code.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your heading up!
Unfortunately, i work at 2 different machine, the machine with actuall code does not have connection to the web browser, therefore , i have to re-type the code manually each time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic