title: Embed PDF in modelAndView
body: <p>I have a WebService that returns a PDF URL.  The problem is that the CMS is terrible, flakey, and that document may not even exist. (or there may not be a network connection to the CMS server)  </p>
  
  <p>I am using Spring 3.2 MVC and my controller is simple enough:</p>
  
  <pre><code>modelAndView.addObject("documentURL", service.getCmswsGetDocumentUrl());
  </code></pre>
  
  <p>and the view:</p>
  
  <pre><code>&lt;object data="${documentURL}" width="600" height="800" type='application/pdf' &gt;
  </code></pre>
  
  <p>This all works fine if the document exists.  </p>
  
  <p>However, I want to be able to do, say a javascript alert() or something if the document is not there.  </p>
  
  <p>Is there a way to embed the pdf in the modelAndView like</p>
  
  <pre><code>modleAndVIew.addObject("pdf",file);
  </code></pre>
  
  <p>Or some way that I can add the data to the html object through jQuery?  </p>
  
  <p>I just don't want to make 2 calls, one to retrieve the document to see if I can, then one to actually retrieve the document in the html object tag.</p>
  
  <p>Any ideas?</p>
  
  <p>Adendum Edit:</p>
  
  <p>Can I do something like this?: 
  <a href="https://stackoverflow.com/questions/2429934/is-it-possible-to-put-binary-image-data-into-html-markup-and-then-get-the-image">Is it possible to put binary image data into html markup and then get the image displayed as usual in any browser?</a></p>
  
  <p>where I base64 encode the PDF in the controller and pass that to the view?</p>