0

I am using Struts 1.x and jsp as view to display. Want to display the entire xml file as it is in a new pop-up window when a link is clicked in jsp. So far I have managed to open the pop-up window but I get a blank window and save/open/cancel links in browser(IE9). When clicking on save I get as 'url.do' but I just want to display the xml content as it is in browser, just don't want to save.

Here is what I wrote in javascript function

function viewXML(bcFileNo){
popupwin = window.open("about:blank", "popupwin", "toolbar=no, resizable=yes, menubar=no, scrollbars=yes, status=no, location=no, width=900 , height=400");
var form = document.forms['BirthCertificateForm'];
form.action = "/Vista-Web/birthCertificateOverview.do?method=viewBirthCertificateDetails&bCertFileNo="+bcFileNo;
form.target = "popupwin";
form.submit();
form.target = "_self";
}

Here is what I wrote in Action class

String xmlContent = getXMLContent();
byte[] birthCertBytes = xmlContent.getBytes();
// set xml content
response.setContentType("html/xml");
// write the content to the output stream
BufferedOutputStream outStream = new BufferedOutputStream(response.getOutputStream());
outStream.write(birthCertBytes);
outStream.flush();
outStream.close();
Roman C
  • 49,761
  • 33
  • 66
  • 176
codingNubie
  • 67
  • 1
  • 9

3 Answers3

0

Try

response.setContentType("application/xml");
response.addHeader("Content-disposition", "inline");

instead.

peabody
  • 553
  • 5
  • 11
  • Tried that too but still getting the same output...also tried "xml". – codingNubie Jul 29 '14 at 06:34
  • Updated my answer to include content-disposition inline. Didn't think that'd be necessary, but just in case. – peabody Jul 29 '14 at 06:57
  • Hi, Didn't worked bro even after adding `response.addHeader("Content-disposition", "inline");`. Anyway, thanks for help. Got it working. I was forwarding to some other url in action class after writing using output stream. Set the return to null and it is working fine. I am able to view the xml in popup. – codingNubie Jul 29 '14 at 07:58
0

Did you tried adding the content disposition in the response ?

If not try that first. And it may be useful for you Content Disposition

Community
  • 1
  • 1
Miko
  • 2,615
  • 9
  • 33
  • 58
0

Thanks for help. Got it working. I was forwarding to some other url in action class after writing using output stream. Set the return to null and it is working fine. I am able to view the xml in popup.

codingNubie
  • 67
  • 1
  • 9