We help IT Professionals succeed at work.

Java Servlet to Handle HTTP POST with byte[ ] Data

cgray1223
cgray1223 asked
on
819 Views
Last Modified: 2012-02-14
Hello,

I need to retrieve data that is being HTTP POSTed to my Java Servlet and the form being posted is sending a byte[].  I have the below doPost method of my Servlet class, is this the best way to retrieve the byte[] data?


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          byte[] imageBytes = request.getParameter("DATA").getBytes();
    }

Open in new window

Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:
what is the source of this byte [] data?
How do you post it on the previous page?
Does it come from a file?

Author

Commented:
there is a flash component that is posting it to the servlet endpoint.
Awarded 2011
Awarded 2011
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
Are you getting a valid byte array?

Author

Commented:
I'm waiting on the flash implementation but trying to test without that.  I'm struggling trying to find a way to create a client that sends binary data.  Any ideas?
Awarded 2011
Awarded 2011

Commented:
why do you need to send binary data to servlet?
servlet is primarily  for getting stuff from the form which is filled in by a user
CERTIFIED EXPERT
Top Expert 2016

Commented:
Try just writing to  a HttpURLConnection via a DataOutputStream. You can call setDoOutput(true) on it first

Author

Commented:
I need to create an image of a display which is a flash component that displays some images floating around with some visual effects.   Flash is taking a screen capture and I need to create a real image out of it on the Java side as I have access to the server itself while flash doesn't
CERTIFIED EXPERT
Top Expert 2016

Commented:
e.g. you could use the above method with a BufferedImage holding the screen shot got from a Robot and instead of the DataOutputStream write the image to the output stream of the connection with ImageIO
CERTIFIED EXPERT
Top Expert 2016

Commented:
I guess you saw this link:

I'm curious to know how that answered your question cgray1223  ...

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.