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,040,783
  • 362
  • 3,548
  • 3,513
Gaurav Agarwal
  • 18,061
  • 28
  • 101
  • 161

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,061
  • 28
  • 101
  • 161
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,121
  • 8
  • 39
  • 52