return a pdf in browser from web service
i am relative new in java development.. I want to create a web service (jax-ws)/web application that will rec开发者_如何学Pythoneive some input and generate pdf, and then open the pdf in the browser. I manage to create the pdf (using itext) and open it in the broswer using servlet (with FileInputStream etc). However i do not know, how to return the servlet from the web service. What should I do, so when I call the web service to receive a pdf via the servlet ?
If you've returned PDF from servlet, it means your servlet sent PDF stream as output and probably set content type as "application/pdf". This works fine in the browser and this is the right way to do it.
However, you cannot easily invoke web service (no matter whether it is JAX-WS or any other stack) from the browser. Web service call requires POST and strictly defined SOAP content. You can, however, use AJAX to call web service, but that is a different story (also look at REST).
If you want to return binary data from web service (please keep in mind that web-services are for machines, not for humans using web browsers), you have two options: either serialize the binary data using base64 or use multipart HTTP response (MTOM standard, see for instance: http://www.mkyong.com/webservices/jax-ws/jax-ws-attachment-with-mtom).
精彩评论