aspose file tools*
The moose likes Struts and the fly likes How jsp and a pdf document displayed in the same browser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How jsp and a pdf document displayed in the same browser?" Watch "How jsp and a pdf document displayed in the same browser?" New topic
Author

How jsp and a pdf document displayed in the same browser?

Kevin Zhang
Greenhorn

Joined: Dec 09, 2008
Posts: 6
I need to display a pdf document within a frame in a JSP page.

In this JSP page, the left frame is a navigation menu.

The right frame is pdf content.

I use struts 1.3 and tiles to implement frames.

To generate pdf ,I use itext.

Here is the sample code

public ActionForward doGenerateLeterPDF(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse response) throws WebException {
try{
Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("Hello World"));
document.close();

response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
}catch(Exception e)
{
logger.error("Exception: " + e);

}

return null;

}

However, after I execute this action class, the pdf displayed in full screen

My request is pdf content only staying in one frame

Any clues on how to implement this?

Thanks,
kapil munjal
Ranch Hand

Joined: May 11, 2004
Posts: 298
I am also facing the same issue. Please provide some link or tell us how to do it.


Kapil Munjal
SCJP 1.4, SCWCD 1.4
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42612
    
  65
The code shown above needs to be executed when the URL of the frame is accessed, not when the URL of the page itself is accessed.


Ping & DNS - my free Android networking tools app
 
jQuery in Action, 2nd edition
 
subject: How jsp and a pdf document displayed in the same browser?