We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

writing to response stream from action

MitchBroadhead
on
Medium Priority
314 Views
Last Modified: 2008-03-10
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.
Comment
Watch Question

Commented:
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))

Commented:
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)
CERTIFIED EXPERT
Top Expert 2004

Commented:
I think you will need to write a servlet, not a Struts action to do this task...

Author

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

Author

Commented:
fixed

used ByteArrayOutputStream to store the output of itext htmlwriter, then usedbaos.toString() to pump into response.getWriter().
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.