I am using struts2
framework and dojo
for ui. I want to display a pdf in new browser window. I am getting pdf inputstream from server via normal ajax call get method(didnt use dojo ajax call. used native js ajax call ).
How to view pdf string in a new browser window?
js code:
/two inputs to get pdf file/
var selectedFileSlot={"END407":"report_28_03_13.pdf","END408":"[B@cef121c","END409":"*.pdf;*.doc;*.docx;*.odt;*.ods","END410":"5242880"}
var selectedNode= {"objectID":"22df1b2601a3552f24e5f011abc27f86","specID":"2001","entityConcreteID":"11000"}
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
alert(xmlhttp.response);
window.open(xmlhttp.response);//not able to open in new browser window
}
}
xmlhttp.open("GET","downloadDocument.action?selectedNode=" + JSON.stringify(selectedNode) + "&selectedFileSlot=" + JSON.stringify(selectedFileSlot),true);
xmlhttp.send();
struts.xml code:
<action name="downloadDocument" class="commonAction" method="downloadDocument">
<interceptor-ref name="sessionStack"></interceptor-ref>
<interceptor-ref name="cachingStack"></interceptor-ref>
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${fileFileName}"</param>
<param name="bufferSize">1024</param>
</result>
</action>
action class code:
commonDTO.setSelectedNode(this.selectedNode);
commonDTO.setSelectedFileSlot(this.selectedFileSlot);
byte[] bytes = commonDAO.getDownloadDocument(commonDTO); //getting pdf as byte array
inputStream = new ByteArrayInputStream(bytes);