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 9313509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:54:08+00:00 2026-06-19T01:54:08+00:00

i am submitting form with text and file types input fields and using this

  • 0

i am submitting form with text and file types input fields and using this code to get text data

but the problem is that

List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
    // Process normal fields here.
    //Taking all text and doing task
    System.out.println("Field name: " + item.getFieldName());
    System.out.println("Field value: " + item.getString());
} else {
    // Process <input type="file"> here.
    //And Leaving this at this time

}            
}

if i parses the request and iterate it from one BY one and then in formField i used to get all text parameters and after it i again used this code in file type condition to upload file so it doesn’t parse again

List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
// Process normal fields here.
//Leaving this section this time
} else {
// Process <input type="file"> here.
//Use to Upload file
System.out.println("Field name: " + item.getFieldName());
System.out.println("Field value (file name): " + item.getName());
}            
}

so why its happening…and what should be the solution for this…????

  • 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-19T01:54:09+00:00Added an answer on June 19, 2026 at 1:54 am

    A HTTP request can be parsed only once because the client has sent it only once. The HTTP request is already consumed in its entirety during the first parse. It is not available anymore during any subsequent parse attempt on the same request.

    It you want to parse it twice, then the client has basically to send it twice. However, you can’t ask/expect a client to do that, that makes no utter sense. Just parse it once and look for a different solution for your concrete functional requirement. E.g. reuse the same items list for both loops.

    List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
    
    for (FileItem item : items) {
        if (item.isFormField()) {
            // Process normal fields here.
        }
    }            
    
    for (FileItem item : items) {
        if (!item.isFormField()) {
            // Process file fields here.
        }
    }            
    

    Note that this is basically inefficient code. So, I’d rethink twice about your functional requirement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine this simple form for uploading a file: <form action=upload enctype=multipart/form-data> <input type=text name=name/>
Upon submitting this form on my site. It send me to a page that
I have a index.jsp file that has two different types of forms <form action=searchpath
I'm writing the code for a form, and submitting it to a php file
It's not the only remote form I'm using, but I can't see the problem
I'm wondering why this is happening: I'm sending file data with form in POST,
I have a webpage that contains a form with several text fields and an
I am submitting a single text area form via :remote => true. It works
I'm submitting a form using an ajax request (POST method), and checking the HTTP
I've got a standard login form submitting data to a Codeigniter function to do

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.