Solved

writing to response stream from action

Posted on 2004-03-30
7
284 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits  challenge 7 62
topping3 challenge 14 52
groovy example issue 10 71
Eclipse IDE - Cannot copy/paste from console output 8 71
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now