0

I'm not getting my error maybe someone can help... this is my jsp code :

<html> <body> <form action="UploadServlet" method="post" enctype="multipart/form-data"> <fieldset> <legend>Read a CSV File</legend> <span class="help-block">Uploads the csv to the server and executes the checked task.</span> <input type="file" name="file" size="50" /> <br> <br> <label class="radio"> <input type="radio" name="fileOptions" id="import" value="import" onchange="showRootDirectoryDiv()" checked>import : create tasks from csv import file </label> <label class="radio"> <input type="radio" name="fileOptions" id="create" value="create" onchange="showRootDirectoryDiv()">create : create directory from root-directory and import file </label> <label class="radio"> <input type="radio" name="fileOptions" id="differ" value="differ" onchange="showRootDirectoryDiv()">differ : differs tasks from csv import file to jira tasks of a specific FixVersion and creates a csv file with tasks, which are not in jira and creates a report about occurrence of all tasks (jQL-query is taken from properties) </label> <br> <div id="root-directory"> <label>Enter the root-directory</label> <input type="text" name="root-directory-create"> </div> <br> <button type="submit" class="btn">Upload File</button> </fieldset> </form> </body> </html> 

So now

 String uploadOption = request.getParameter("fileOptions"); 

should always return a value because there's always a checked radio button (import by default).

But I'm ALWAYS getting null no matter what's selected?? I'm not getting it checked the name like 5 times but I'm always getting null.

5
  • Your form send a Post request. Make sure that the code is in doPost methode of your servlet. Commented Mar 20, 2014 at 17:32
  • con you post your servlet code Commented Mar 20, 2014 at 17:40
  • 1
    The request is mulipart as you are using enctype="multipart/form-data"in which request parameters are unavailable unless you parser the request explicitly using some mulpipart parser like Apache Common FileUpload (The Servlet API does not support this functionality out of the box). Commented Mar 20, 2014 at 17:44
  • try to use <input type="button"> instead of <button> tag. Commented Mar 20, 2014 at 17:44
  • paste the stacktrace or exception.. Commented Mar 21, 2014 at 7:15

1 Answer 1

1

Its because you are using enctype="multipart/form-data". When you do that, request.getParameter no longer works. You have to retrieve everything from the request either by request.getPart if you are on Servlet 3.0 or higher, or use the Apache Commons File Upload Library to retrieve everything from the request (not just the file).

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Apache COmmons File Upload was the key.. request.getPart returns null aswell :/ I got a detailed solution how to get the data here : stackoverflow.com/questions/5730532/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.