This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 41155
    
  45
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
 
Don't get me started about those stupid light bulbs.
 
subject: How jsp and a pdf document displayed in the same browser?
 
Similar Threads
iText in Struts
Trouble in generating pdf reports with Jasper and iText
I am trying to generate a PDF file in Hibernate
feeding byte[] to crreate a pdf
Images in PDF files problem for ServletOutputStream