• Post Reply Bookmark Topic Watch Topic
  • New Topic

Download Component functionality using servlets

 
shyam jakki
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Hi

I have a question to Develop the Download component functionality using servlets/jsp.

When the user clicks the download on the jsp/html page(file can be excel or PDF file etc).

It opens a Dialog box and prompts to open/save it to the appropriate folder from the server.

I apprecite if anyone helps me and provide good example with code and design Using servlets/JSP.

Regards
Shyam
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ February 24, 2006: Message edited by: Bear Bibeault ]
 
shyam jakki
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for the reply
But I'm not able to open the link.

Please provide.

Regards
Shyamm
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That wasn't a link you were supposed to follow, that's the code to achieve the download functionality you asked about.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shyam jakki:
Hi
Thanks for the reply
But I'm not able to open the link.

Please provide.

Regards
Shyamm


Bear was showing you how to create an HTML Hyperlink.
The filename was fictitious and clearly wouldn't actually work on your system.
If you want more detailed help, you will need to provide a more detailed question.


Do you already have code for streaming files?
What part are you stuck on?
What have you written so far?
 
shyam jakki
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks for the reply. I thought that it leads to the code that i'm looking at.
I mean that
How to write a servlet/jso/struts code to download a file (into excel,pdf or text) on the client madhine.

Regards
Shyam
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the file already exists on the server, you don't need to write any code at all... just provide a link to it like I showed.

If you are asking about generating a PDF or other file on-the-fly, from info in a DB for example, that's a different question.

As Ben said, better questions get better answers.





[klunk]
[ February 24, 2006: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If just adding a hyperlink to the file isn't enough and you want to write the code to stream the file itelf, I would start by reading the file with
java.lang.String)" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getResourceAsStream(java.lang.String)
.
You can then write the stream to the ServletOutputStream
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#getOutputStream()

If you want to insure that the prompt to save the file will always come up (as opposed to just having the file open in the associated application), you'll want to set both the contentType and the ContentDisposition headers to contain values that the browser won't recognize.

http://simple.souther.us/ has an example app called SimpleStream that streams images to the browser. This should contain all the sample code you'll need.
[ February 24, 2006: Message edited by: Ben Souther ]
 
shyam jakki
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I would appreciate if you provide me how to design and write the code using servlet for file Download(files might be either excel,pdf or doc)

Thnaks and Regrds
Shyam
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!