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

  • SEARCH
  • Home
  • 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 9162229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:09:39+00:00 2026-06-17T14:09:39+00:00

The html snippet sends a post request to a servlet named servlet . The

  • 0

The html snippet sends a post request to a servlet named servlet. The request is of type multipart/form-data.But servlet finds nothing and prints null for the name of the part I try to retrieve. Why is that ?

<form method="post" action="servlet" enctype="multipart/form-data">
        <input type="file" value="browse" name="FileShared" />
        <input type="submit" value="submit" />
 </form>

import javax.servlet.http.Part;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

    @Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/plain");
    //String fileName = request.getPart("FileShared").getName(); 
    // Throws a nullpointer exception if I don't comment the above statement
    PrintWriter writer = response.getWriter();
    //writer.println(fileName);
    Collection<Part> c = request.getParts();
    Iterator i = c.iterator();
    while(i.hasNext()) {
        writer.println("Inside while loop"); // This statement never gets printed
        writer.println(i.next());
    }
    writer.println("outside while loop"); // Only this statement gets printed
}
  • 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-17T14:09:41+00:00Added an answer on June 17, 2026 at 2:09 pm

    If you want to use Servlet 3.0 HttpServletRequest#getParts() method , then you must annotate your servlet with @MultipartConfig.

    Example :

    @WebServlet(urlPatterns={"/SampleServlet"})
    @MultipartConfig
    public class SampleServlet extends HttpServlet {
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a html snippet dynamically which contains named anchors and
I am using jQuery and sending a post request to a page which sends
I have an HTML page with a JavaScript code that sends AJAX request. The
Imagine i have this HTML snippet 4 times over for four different sections of
Consider the following HTML snippet. The desired effect is to have a dropdown be
A sample of the HTML snippet is here: <select name=paytitle id=paytitle> <option value=Budget Keeper
I run the following html snippet in IE8 and IE7 with non-English characters (we
I have some html snippet <div id=title>This is title<span id=close>X<span><div> The width of this
Consider the following HTML snippet containing some javascript utilizing prompt and unload . The
I'm using e4x to generate a HTML-snippet for my users which they can copy

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.