request getParameter is always null when using enctype=“multipart/form-data”

前端 未结 2 1768
孤城傲影
孤城傲影 2020-12-04 02:47

I am performing validation of inputted data such as email, password, name, etc. But I am already stuck on the first stage of validation which is to check if User entered not

相关标签:
2条回答
  • 2020-12-04 03:07

    Unless you're planning to use your form for uploading a file, you don't need to specify the encoding type of "multipart/form-data".

    <form method="POST" action="signup">
        <input type="text" name="email" placeholder="tonystark@mail.com">
         <input type="submit" value="Submit">
    </form>
    

    The last paragraph in your link states:

    "When using enctype="multipart/form-data", all parameters are encoded in the request body. That means that request.getParameter(...) will return null for all posted parameters then."

    Input type: email

    Email is an html5 input type. How To Use The New Email, URL, and Telephone Input Types.

    0 讨论(0)
  • 2020-12-04 03:09

    Since it is a multipart/form-data (usually used for the puropose of uploading one/more file(s)) form the request.getParameter() method will always return null.

    You can try

     <form method="POST" action="signup" enctype="application/x-www-form-urlencoded">
    

    Or completely remove the enctype parameter.

    Some references in another SO question.

    How to upload files to server using JSP/Servlet?

    0 讨论(0)
提交回复
热议问题