Stack Exchange
Does form with enctype="multipart/form-data" cause problems accessing a hidden field
I have created a hidden form element
<form name="UploadImage" enctype="multipart/form-data" method="post" action="UploadImage">
    <label>
        </label>
    <input name="imgUploadObjId" id="imgUploadObjId" value="52" type="hidden">

    //rest of the form here

</form>

And I am trying to get the value with this line in a servlet (as I have done before):
int objId = Integer.parseInt(request.getParameter("imgUploadObjId"));

But I get this (line 33 is the line above):

java.lang.NumberFormatException: null
              java.lang.Integer.parseInt(Unknown Source)
      java.lang.Integer.parseInt(Unknown Source)
      web.objects.UploadImage.doPost(UploadImage.java:33)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Is there something different about a form with enctype="multipart/form-data"? Or can you see some other error.

This happened with me too.I wanted to send the values of multiple checkboxes using html:checkbox with the same name attribute so that the values were being stored in struts forms in an Integer array.However after selecting thousands of checkboxes, I found that few values in the middle would skip over at specific indices when I was using request.getParatemeterValues("myAttribute").They were simply empty.Since I was not uploading any file on the form,removing the enctype="multipart/form-data" from the form enabled me to send ALL the values correctly.

The servlet parses the parameters by default using application/x-www-form-urlencoded encoding. The multipart/form-data encoding however isn't supported in servlets until Servlet 3.0. The getParameter() calls will all return null.
In Servlet 3.0, you should have used HttpServletRequest#getParts() instead to get all parts of a multipart/form-data request, including normal form fields. Prior to Servlet 3.0, you should have used Apache Commons FileUpload to parse multipart/form-data requests. See also the following answer for a detailed example of both approaches: How to upload files to server using JSP/Servlet?
Note that if you aren't using any <input type="file"> field at all, then you can just leave the encoding away from the <form>. It will then default to application/x-www-form-urlencoded.

+1. For suggesting to leave out enctype attribute if file upload is not needed.

As a workaround, you can also add the required hidden parameters as GET parameters in the form's action attribute:
<form name="UploadImage" enctype="multipart/form-data" method="post" action="UploadImage?imgUploadObjId=52">

    //rest of the form here

</form>

this will allow the request.getParameter("imgUploadObjId") call to work.

Indeed there is something different.
request.getParameter will only work for hardcoded URL parameters specified in action attribute of <form> element.  In your case it does not contain any.
All other parameters will be incoded into the form itself, which you have to process by parsing HTTP request's input stream directly.
Fortunately, you are not the first and there are some good open-source libraries that take care of this.
I've been using Apache FileUpload.  You create a parser and pass a request object to it and then iterate through different items.  One of them will be your hidden field.

The multi-part encoding shouldn't affect hidden text fields. It is likely something else. Can you post more of the HTML/Servlet code?

Not sure if this helps, but I have used multipart forms in jsp pages which are submitted to a struts servlet and these pages have hidden fields which are received in my Struts Action classes (wrapped in Struts ActionForm), so I don't think there is any hard stop here.
Have you tried receiving this value as String and seeing what actually comes there?

You'd check the servlet code itself. Are you getting the request? Can you debug the app in order to see which variables are present in the environment when you try to get the value and parse it.

Looking at Firebug I am getting the correct values in the request, but based on what everyone else says I have to do something different. I will use ApacheFileUpload and loop through the elements.

I only had the id atttribute set for the field and it didn't show up in the List items list. When I added the name attribute, it showed up.
