In this link it says:Handles the user’s request to generate the HTML for the report and writes the HTML directly to the response object.
Now in my code, I have:
PrintWriter out = response.getWriter();
crystalReportViewer.processHttpRequest(request, response, context,null);
If I understand correctly, the processHttpRequest will itself do something like response.getWriter().print(.....).
So is the code creating 2 instances of PrintWriter?
Response object will return the same writer every time. You can use these writers interchangeably:
The output is as expected because
writerAandwriterBare actually pointing to the exact same instance ofPrintWriter.I don’t know whether it is stated as such in the specification, the Javadoc only says:
That being said your code is not safe for two reasons:
crystalReportViewermight callresponse.getOutputStream()which breaks the contract quoted aboveif you print something first and then pass the
responseto thecrystalReportViewerchances are your output will break thecrystalReportVieweroutput as it will be prepended.