Highlighted

Receiving PDF object as request in Servlet

Avatar

17-12-2008

I have a PDF form with its Submit button property set to "PDF"..I can change it to XDP if this does not solve my problem.



My requirement is, users can download the form over the web and save it to their desktop. Once they submit the form, I would like to invoke a servlet program which would then email the form with the data users fill out to designated address.



Right now, I have written a Java Mail program that does the emailing part. But I am not able to send the PDF that will submitted, as an attachment with the email. I am trying to read this form but not able to do so:



Here is the exception that I receive:

"the request doesn't contain a multipart/form-data or multipart/mixed stream,content type header is application/PDF"



How do I read the PDF form that users submit?



Here is a sample from my code: or is my approach wrong??



boolean isMultipart =

ServletFileUpload.isMultipartContent(request);

if (isMultipart) {

}

else {

FileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new

ServletFileUpload(factory);

List items = null;

try {

items = (List) upload.parseRequest(request);

}

catch (FileUploadException e) {

e.printStackTrace();

}

Iterator itr = (Iterator) ((java.util.List) items).iterator();

while (((java.util.Iterator) itr).hasNext()) {

FileItem item = (FileItem)itr.next();

if (item.isFormField()) {

}

else {

try {

String itemName = item.getName();

InputStream attach = (InputStream) item.getInputStream();