• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to download binary file in jsp

 
bappa
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am trying to download binary file by a jsp file but it is showing the content (not all) on the browser. I want to save that file automatically to the client machine in a specified location. Please help.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs aren't meant for streaming binary content (and for all practical purposes, they can't). Use a servlet instead.
 
bappa
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then how to do it by servlet. please let me know... Give one sample code.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An example can be found under "Simple Stream" in the Code Barn.
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
An example can be found under "Simple Stream" in the Code Barn.


How do we render the images, if i try to invoke the servlet directly it gives:"The following image files are located under the WEB-INF directory and, thus, can not be seen with a browser unless streamed through the StreamServlet: "
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly what that says. Any resources under WEB-INF are not directly accessible by URL.
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Exactly what that says. Any resources under WEB-INF are not directly accessible by URL.


Does that mean this example is just to show how to disallow stream of an image as compared to 'how to show a stream through a servlet?'
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The example shows how to stream a resource through a servlet. This is useful for not only controlling access to resources hidden under WEB-INF from direct access, but for controlling the response headers so that the download acts in ways that you want.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic