• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

writing to response stream from action

trying to call an action in a jsp page to return some html on http response stream, but it doesn't seem to like it.  i am using the itext library's html writer.

i have an action-mapping where /ledger.do maps to Ledger.class which is an action.
in ledger.jsp:
<jsp:include page="/ledger.do" />

in Ledger.java:
ServletOutputStream out = response.getOutputStream();
response.setContentType("text/html");
HtmlWriter.getInstance(document, out);

the problem is that the http headers have already been sent so...
is there any way to write html back to the response stream?
I don't mind changing class type to httpservlet.
0
MitchBroadhead
Asked:
MitchBroadhead
1 Solution
 
searlasCommented:
Use getWriter, not getOutputStream and you won't have a problem.
(the jsp's implicit out variable is a wrapper (indirectly) for response.getWriter - and you cannot call both getWriter and getOutputStream without throwing an exception (according to the specs))
0
 
searlasCommented:
Think I misinterpreted your question.

Have you tried increasing the buffer in the jsp page (thereby giving your action and itext more chance of altering the headers before they are written)
0
 
TimYatesCommented:
I think you will need to write a servlet, not a Struts action to do this task...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
MitchBroadheadAuthor Commented:
ideally i would like to output to the http stream without headers, to allow the html to be embedded into the page
0
 
MitchBroadheadAuthor Commented:
fixed

used ByteArrayOutputStream to store the output of itext htmlwriter, then usedbaos.toString() to pump into response.getWriter().
0
 
Computer101Commented:
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now