Solved

writing to response stream from action

Posted on 2004-03-30
7
287 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.
0
Comment
Question by:MitchBroadhead
7 Comments
 
LVL 7

Expert Comment

by:searlas
ID: 10713534
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
 
LVL 7

Expert Comment

by:searlas
ID: 10713543
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
 
LVL 35

Expert Comment

by:TimYates
ID: 10713560
I think you will need to write a servlet, not a Struts action to do this task...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:MitchBroadhead
ID: 10713645
ideally i would like to output to the http stream without headers, to allow the html to be embedded into the page
0
 
LVL 1

Author Comment

by:MitchBroadhead
ID: 10715844
fixed

used ByteArrayOutputStream to store the output of itext htmlwriter, then usedbaos.toString() to pump into response.getWriter().
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10908985
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 3 50
PDFBox - convert image to PDF, PDF resolution 3 118
simple java question 3 44
expectj telnet failing 5 26
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now