Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts action and JSP chaining

 
suu boy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi their,
presently i am using struts to send dynamically generated PDF files to browser , struts is the web framework I am using , along with PDF file I would like to display JSP content also , to achieve this I am setting the content of PDF file in action class and forwarding request to some preconfigured jsp file where remaining page content will be generated , I am getting following exception when request reaches my JSP pages

exception content="[OutputStream already obtained]: java.lang.IllegalStateException: OutputStream already obtained"


here is the code snippest in action calss

public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
OutputStream sos=null;
logger.debug("Writing PDF Stream...............");
StringBuffer sbFilename = new StringBuffer();
sbFilename.append("filename_");
sbFilename.append(System.currentTimeMillis());
sbFilename.append(".pdf");
this.getResponse();
getResponse().setContentType("application/pdf");
getResponse().setHeader("Content-Disposition", "attachment; filename=\"PurchaseOrder.pdf\"");
byte[] tmpData = baosPDF.toByteArray();
System.out.println("Data Retrieved.." + tmpData.length);
sos = getResponse().getOutputStream();
sos.write(tmpData);
sos.close();
logger.debug("completed writing PDF Stream...............");



//some code..................
// some code ...........................
return forward;
}


can any one help out to resolve this issue , I would like to write some data response stream at action classes and again I want to add jsp dynamic content to response stream,
yes i am talking about kind of servlet chaining in struts,
how can i avoid this exception and achieve my goal

with regards,
Suhi...............
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic