Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7950379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:15:07+00:00 2026-06-04T02:15:07+00:00

If i Upload a file to my servlet like this: HttpClient httpclient = new

  • 0

If i Upload a file to my servlet like this:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.tumblr.com/api/write");

try 
{
    MultipartEntity entity = new MultipartEntity();
    entity.addPart("type", new StringBody("photo"));
    entity.addPart("data", new FileBody(image));
    httppost.setEntity(entity);
    HttpResponse response = httpclient.execute(httppost);
} 
catch (ClientProtocolException e) {} 
catch (IOException e) {}

How can I retrieve the content at the servlet?

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws  IOException 
{
     request.???
}
  • I’m using Google App Server as my Servlet API
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:15:09+00:00Added an answer on June 4, 2026 at 2:15 am

    If the version of your Servlet Container or Server or Engine < 3.0 (like 2.5 or earlier) , you may want to take advantage of the third-party Library Apache Commons FileUpload. Although the file implied an use for uploaded Files, it also deals effectually with uploaded posted Data from POST-Methods like it explained here.

    the Servlet API, from the version 3.0 offers some calls in oder to deal with posted Data, with was sent within a POST-Request. the only requirement is that the MIME-Type encoding of your entity content is “multipart/form-data“.

    then your can retrieve each “part” of your content using either:

    1. getPart(String partName): where “partName” is the name of a part of your Multicontent entity.

      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws  IOException 
      {
          String partName = "type"; // or "data"
          Part part = request.getPart(partName);
      
          // read your StringBody type
          BufferedReader reader = new BufferedReader( new InputStreamReader(part.getInputStream()));
          String line ="";
      
          while((line=reader.readLine())!=null)
          {
              // do Something with a line
              System.out.println(line);
      
          }
      
          // or with a binary Data
          partName="data";
          part = request.getPart(partName);
      
          // read your FileBody data
          InputStream is = part.getInputStream();
          // do Something with you byte data
      
          is.read();
          // is.read(b);
          // ..
      
      }
      
    2. getParts():

    it achieves the same results as getPart(partName), whereas the given data here a collection of all part of the sent data. to retrieve each par of the Part of this collection, just use thread-safe iteration over the collection:

    Iterator<Part> iterator = request.getParts().iterator();
           Part parts = null;
           while (iterator.hasNext()) {
           parts = (Part) iterator.next();
              //rest of the code block removed
           }
        }
    

    Because the getPart()/getParts() only works beginning at the Servlet 3.0 version, you’ll make sure to use the supporting Servlet container and/or upgrade your current Servlet Container. some Server or Servlet container that supports 3.0:

    1. tomcat 7.0:
    2. Jboss Web
    3. Resin
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a seam app and would like to use the MultiPowUploader ( http://www.element-it.com/multiple-file-upload/flash-uploader.aspx
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I'm trying to write a servlet, that can upload a file from client to
How do I upload a file from a Java servlet to a location on
I used this example (http://reecon.wordpress.com/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/) to upload file from android device to server, it
I'm running a servlet in Tomcat 6.0.26. The servlet accepts file upload from the
I am attempting to upload a file from my html page to my servlet
I have a SpringMVC web service for uploading files which looks like this: @RequestMapping(value=/upload.json,
I have a file upload form that is being posted back to a servlet
I am using jsp/servlet for file upload, i am able to upload a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.