0

I have a view page using JSP. I have enctype="multipart/form-data" and also have dropdown field using select option.

Here my code:

    <form id="formNaikLimit" action="" enctype="multipart/form-data"
                method="post">
                              <label for="jenisKartuLimit">Jenis Kenaikan Limit Kartu
                                Kredit </label> <select class="form-control mandatory"
                                 name="jenisKartuLimit" required="required">
                                <option value="Sementara">Sementara</option>
                                <option value="Permanen">Permanen</option>
                            </select>
                                    <div class="form-group-1" style="">
                                        <input id="attachKtp" name="attachKtp" type="file" class="file"
                                            required="required" accept=".png,.jpg,.pdf">
                                    </div>
                                    <div class="alert alert-danger"
                                        style="margin-top: 10px; display: none;" id="sample"
                                        data-for="attachKtp">Attachment KTP wajib diisi</div>
                                    <br />
</form/>

And this is my servlet:

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


try {
            this.action = request.getParameter("action");
            String temp = request.getParameter("jenisKartuLimit");
}catch(Exception e){}
}

when i try to debug, i always get temp value is null, why i can't read the selected value of jenisKartuLimit?

Thanks for every response.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user3505775
  • 339
  • 2
  • 6
  • 20

2 Answers2

0

Is enctype="multipart/form-data" option of form doesn't allow other form data to be submited? if it doesn't allow it then what are the other options I have to send this additional textfield to the server. No there is no issue with using enctype="multipart/form-data". You can get other fields then file in such form.

While using enctype="multipart/form-data" you can not directly get parameters by using request.getParameter(name);. While using it, form fields aren't available as parameter of the request, they are included in the stream, so you can not get it the normal way. You can find a way to do this in the docs of using commons-fileupload, under the section Processing the uploaded items.

or you can use Servlet 3.0 version , which have multipart support you can get request attribute allong with uploaded file without help of third party api jars.

Sunil
  • 437
  • 3
  • 11
-1

try to add your name property to the option elements

<option name="jenisKartuLimit" value="Sementara">Sementara</option>
<option name="jenisKartuLimit" value="Permanen">Permanen</option>
Y.Ido
  • 333
  • 1
  • 11
  • i already try to add name in every option, but nothing changing – user3505775 Oct 26 '17 at 03:16
  • that's strange. did you do anything else before you post the form ? – Y.Ido Oct 26 '17 at 03:53
  • i think that's strange too, but my code is more complex than the post i made. I tried to print in jquery, i get the value. I try to use String temp = request.getParameter("jenisKartuLimit"); in the first line code. so actually the value is the real value without any changes. – user3505775 Oct 26 '17 at 04:00