2

This may be very simple question but I have been looking around for a while. I am sending two strings to a Java Servlet on Tomcat 7.

multipartContent.addPart("destadd", sb1);
multipartContent.addPart("destfilename", sb2);

I am trying to retrieve these String like this

String destFileName = request.getPart("destfilename").getName();

but in vein. I will appreciate any help.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166

3 Answers3

3

I was running around for two days almost, fianlly I got the answer

Part destFileNamePart = request.getPart("destfilename");
Scanner s = new Scanner(destFileNamePart.getInputStream());
String destFileName = s.nextLine();
Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
1

A little bit late but it may help for someone else:

IOUtils.toString( destFileNamePart.getInputStream() );
0

Have you looked at Get form parameters from multipart request without getting the files.

You can also use utility class such as O'Reilly MultipartRequest and more info here

Community
  • 1
  • 1
TS-
  • 4,311
  • 8
  • 40
  • 52