aspose file tools*
The moose likes Servlets and the fly likes Download file HELP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Download file HELP?" Watch "Download file HELP?" New topic
Author

Download file HELP?

jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
Hi Ben:
I do have a method to specify the mimetype for each file type:


Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Apr 04, 2002
Posts: 180
I am using the method to getMimeType to setContentType


Thanks
jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
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

Joined: Apr 04, 2002
Posts: 180
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Apr 04, 2002
Posts: 180
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Apr 04, 2002
Posts: 180
Ben thanks for your reply, and point out,
I did monitor the log, nothing blow up, Not sure why not working
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Did you fix this?


As it is, len is never being assigned anything.
jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Apr 04, 2002
Posts: 180
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download file HELP?