Does form with enctype=“multipart/form-data” cause problems accessing a hidden field

后端 未结 7 2238
失恋的感觉
失恋的感觉 2020-12-18 05:39

I have created a hidden form element

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-18 06:01

    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 field at all, then you can just leave the encoding away from the . It will then default to application/x-www-form-urlencoded.

提交回复
热议问题