• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

question about sending a jar file to browser

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I was trying to learn an example from Deshmukh's book on page 41. The example use a doGet() method to send a JAR file back to the browser. To my understanding, doGet() method can only send text file, not binary, am I correct? And what's more, since a href can only use GET method, does that mean we normally can't use a href to upload or download a binary file since it is only supported by POST method.
Thanks in advance.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getInputStream() which returns a ServletInputStream and getOutputStream() which returns ServletOutputStream can be used to work with binary data for request/response respectively.
so u can read binary data with GET
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That example shows what the HttpServlet doGet method does after it gets the text request from the browser. You're confusing the http get method and what it can do and the HttpServlet doGet method and what it can do. The http get method has to send text. The doGet method in the servlet can do anything it wants, including writing out the jar to the response.
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yuan Ye:
Hi, I was trying to learn an example from Deshmukh's book on page 41. The example use a doGet() method to send a JAR file back to the browser. To my understanding, doGet() method can only send text file, not binary, am I correct? And what's more, since a href can only use GET method, does that mean we normally can't use a href to upload or download a binary file since it is only supported by POST method.


There appear to be two issues that I think you are confusing or at least mixing together.
First, (as Siddhartha pointed out) a servlet may return any content type from a GET request (or POST request, for that matter). Simply, use the setContentType method to set the MIME type of the content being returned. If that content type happens to be binary data, then use the getOutputStream method on the response object to get access to a binary stream.
Second, you also mention uploading files. You cannot use a GET request (such as an A-HREF tag) to perform file upload; period, end of story. You must use a FORM tag in conjunction with an INPUT tag of type FILE inside of the FORM tags. The method attribute of the FORM tag must be POST and the enctype attribute must be 'multipart/form-data'. You will also need additional support on the server side to process a file upload. Check out the Jakarta Commons FileUpload project for more details.
Cheers,
Bryan
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for replying. Now I am quite clearer about the issure. Thanks again.
 
I think she's lovely. It's this tiny ad that called her crazy:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic