• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pass byte in servlets

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need to pass image as bytes in servlet request parameter
i have set the setters and getters as byte

assuming i have

how do i code it as byte and pass it in servlet. Is it like this
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raw binary data cannot be passed in a parameter. The normal way of handling this is to first encode (Base64 or Hex say) the binary data before sending it as a parameter and then to decode it in the Servlet. BUT - since the data seems to be an image and is likely to be longer than can be sent as a parameter you should consider sending it as the body of a POST then no encoding is required.
 
muntago Richard
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my getters and setters in a java class. how do i pass it to servlet request parameter


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's doing the passing? As already pointed out, you'll need to encode it in BASE64, set all the right headers, and pass it as the POST body of a multipart request with appropriate separators.

If it's being sent from a browser, a multi-part form and file input element will do this automatically. Otherwise, you'll need to find out all about the necessary format. There may be support for such things in 3rd party libraries such as HttpClient, but I'm not sure.
 
muntago Richard
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried to upload image as byte into database from servlets ,it works excellent

as follows




okay now i wants to upload it to database via form input elements

so i code it this way

when i run it, it displays error variable picture not found. if try this



it displays error picture is already define
any help
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic