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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:08:55+00:00 2026-05-29T09:08:55+00:00

I know how to do file upload using Primefaces or using Tomahawk, however, I

  • 0

I know how to do file upload using Primefaces or using Tomahawk, however, I am trying to doing file upload using Apache Commons FileUpload and so far I am having a bit of road block. Even though my form use multipart/form-data, when I submit my form, the content type become application/x-www-form-urlencoded. Here is my code

<h:body>
    <h:form enctype="multipart/form-data">
        Upload File
        <input type="file" name="file"/>
        <p:commandButton value="Submit" action="#{viewBean.submit}"/>
    </h:form>
</h:body>

Here is my ViewBean

@ManagedBean
@ViewScoped
public class ViewBean implements Serializable {
    public void submit() {
        String url = "/FileUploadServlet";
        FacesContext context = FacesContext.getCurrentInstance();
        try {
            String contentType = context.getExternalContext().getRequestContentType();
            context.getExternalContext().dispatch(url);
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Exception when calling Servlet", e);
        } finally {
            context.responseComplete();
        }
    }
}

So when I try to print the content type above, it showed application/x-www-form-urlencoded. If I put ajax="false" to my p:commandButton, then the submit() method is not even invoked, but if I take out enctype="multipart/form-data" (still keep ajax="false"), then submit() is invoked but it is not multipart, it is application/x-www-form-urlencoded, so apache commons fileupload throw an exception since it is not multipart. Seems like whatever I do, I cant seems to get the multipart requrest. Please help

  • 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-05-29T09:08:56+00:00Added an answer on May 29, 2026 at 9:08 am

    So when I try to print the content type above, it showed application/x-www-form-urlencoded.

    The <p:commandButton> sends by default an ajax request of level 1 XMLHttpRequest. This does not support multipart/form-data. Only level 2 XMLHttpRequest supports it, but it’s only supported in the newest browsers (those also supporting HTML5) and not implemented in JSF JS API nor in PrimeFaces JS API.


    If I put ajax=”false” to my p:commandButton, then the submit() method is not even invoked

    This way however a fullworthy multipart/form-data will be sent. That the submit method is not invoked is just because JSF prior to version 2.2 does not support multipart/form-data requests out the box. JSF collects the submitted data by default using request.getParameter() and getParameterMap() on the underlying HTTP servlet request. However, this will return null when an encoding other than application/x-www-form-urlencoded is been used. As JSF determines the to-be-invoked action method based on submitted data, it won’t be able to locate and invoke it when the data is null.

    In theory, if you create a Filter which uses Apache Commons FileUpload or the new Servlet 3.0 request.getPart()/getParts() methods to extract the data from the multipart/form-data request and wraps the current HTTP servlet request with a custom implementation which overrides the getParameter() calls wherein a mapping of the extracted data is been supplied, then JSF will be able to do the needed job based on results of getParameter() calls. You can find a concrete example utilizing the Servlet 3.0 API in this article and the same example which is slightly changed to utilize Apache Commons FileUpload in this answer.

    The upcoming JSF 2.2 will have a new <h:inputFile> component which is bindable to a Servlet 3.0 Part property.

    <h:form enctype="multipart/form-data">
        <h:inputFile value="#{bean.file}" />
        <h:commandButton value="submit" action="#{bean.submit}" />
    </h:form>
    

    with

    private Part file;
    

    JSF 2.2 final release is scheduled for late end of Q1, but is currently available as a snapshot release.

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

Sidebar

Related Questions

I am trying to upload a file using commons-fileupload-1.1.1.jar file (I know it is
I'm trying to create file upload using iframe(ajax effect) but I need to know
I am doing a file upload using PHP, which works fine for a file
I am trying to upload files using Spring CommonsMultipartResolver however the controller is not
Does anybody know how they do multi file upload using only Javascript only and
I am trying to fake a file upload without actually using a file input
I'm trying to upload a picture with https using post method. I already know
I'm trying to make a multi file uploader. I'm using Multiple File Upload Magic
I am trying to create a file upload field that has a little bit
Does anyone know of any methods to create a file upload progress bar in

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.