getting response back from a Java Servlet to Drupal My working scenario is like this,
A webform (suppose an admission form for school) should be there on my drupal site and when a user clicks "submit" button a nicely formatted pdf file should be generated.

my approach is like this:
1. I have created a webform using webform module


I have written a servlet to generate pdf file (currently hosted at another server)
now I want to have communication between my servlet and drupal, so I created a small 
module that will execute custom function whenever user clicks submit button of the webform.


I am using curl to send the form data to servlet and it is working with http code 200.following is my code.

define("URL","http://localhost:8080/pdf?");
//my data actuly its coming from the webform
$fields = array(
  'name'=&gt;'deepak',
);

$fields_string = http_build_query($fields);
drupal_set_message($fields_string);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);
curl_close($ch);


I am getting the PDF file encoding printed in the browser. How can I force User to download it.

please guide me.
To force download, you want to set the proper headers for filename, content-disposition and content-length. In your case, it may need to be set from the Servlet application, but without knowing the details of $response, that's difficult to determine.

In general, though, your headers should look something like this:

'Content-disposition:attachment;filename=foobar.pdf' (content-disposition:inline is the opposite of this)
'Content-length:1234567098'