First of all nice to meet you & I should appreciate you for asking that kind question. Yah. Its possible to have stored the PrintWriter's output to a seperate file into your hard drive. For that I would like to suggest you to try this piece of code.....
Remember to specify the hard drive path of your comp within " ", i.e. something like "C:\\myproject\file.out" and this file has to be created under this folder before compiling your code, otherwise you will be welcome with a compilation error like "file.out does not exist".
Originally posted by sudip ghosh: Remember to specify the hard drive path of your comp within " ", i.e. something like "C:\\myproject\file.out" and this file has to be created under this folder before compiling your code, otherwise you will be welcome with a compilation error like "file.out does not exist".
I do not have a JDK in the computer that I am using right now..So I sould not test by doubts.
I think that if the file is not found then it would create the file and even if it needs the file to be present before writing then also I do not think that compilation would fail.It might fail at runtime.
Hi Martin, Although I understand the literal meaning of the question asked I am not certain of the larger issue that is addressed by finding a solution to the question.
Can you provide more information about the nature of the issue that has lead up this question?
A servlet filter can be used to post-process a response before it reaches the client. We do have control over what is written to the outputstream and we control how and if a printwriter is used. Does this question really pertain to JSPs?
If so, filters will work with JSPs in addition to servlets. But, again, before traveling to far down this road a discussion of the larger issue is needed.
Next, as far as FileWriters, Checked Exceptions, and compilations are concerned, you will receive an error when a declared exception is not handled. You will not, however, receive compile time errors for conditions that can only be determined at runtime. In fact, in this case, you will not even receive a warning.
Thanks for replying, In fact, I have a servlet, and I would like to read the content of the outputstream, before it is flushed to the browser client. So that I could change the content on certain conditions... Martin
Maybe you can think to do not generate this content at certain conditions? You can't control buffering of output stream in servlet container much, so subclass servlet output stream with your stream and use it as it was recommended.
HI! In your example, the filter i must create, does it have to be the first filter called if my application has several filters?? When I'll call responseWrapper.toString(), I will have the html code of the page?? I will have to try it soon!!! Thanks for helping, hope this will solve my problem... Martin
Does'nt seem to work SystemOut always print ""!
I'll check further tomorrow... [ November 20, 2006: Message edited by: Martin Lefebvre ]