0

I want to create a form with two textfields and one fileupload. How can I handle the textfields in my Servlet? It doesn't work with request.getParameter("user").

Here is my form:

<form action="FileUpload" method="post" enctype="multipart/form-data">
    <p><input type="text" name="user" id="user"/></p>
    <p><input type="password" name="password" id="password"/></p>
    <p><input type="file" name="file" size="50"/>
    <p><input type="submit" value="Senden"/></p>
</form>

Thanks for your help

dodu0815
  • 23
  • 4

2 Answers2

0

While your form is declared as multipart/form-data then you need to check if the stream contains form field type or a multipart type.

MrSimpleMind
  • 7,890
  • 3
  • 40
  • 45
0

I think Unable to read form field in servlet should help answer your question. In essence you need to create a new MultipartRequest object using the request as an argument and then call getParameter on that object. Like this:

String dir = directoryToSaveFileTo;
MultipartRequest r =new MultipartRequest(request, dir);
String User = r.getgetParameter("user");
Community
  • 1
  • 1
saml
  • 794
  • 1
  • 9
  • 20