Saturday, June 12, 2010

Knowing the exact location of error in your jsp

Actually it's been several times I have to deal with error happening during jsp rendering. To be more exact, the error doesn't lie in the jsp page but in the content prepared before rendering the jsp. Usually what I do is just removing part by part of the jsp page until I can locate the part that caused the rendering error. I keep on doing it until I remember that during page rendering a buffer is used and the buffer size itself is configurable.

Here's in short of how to do it:
- Insert the following page direction to the top of the jsp page
<%@ page buffer="none" %>
- Try to open the page again in the browser and view the source
- The last position of the source page will show exactly the position of the error, i.e. the position before the source of the error
- After you've managed to fix the error, don't forget to remove the page directive. It will certainly degrade the performance if you leave it there