Ok, perhaps some of you remember my post about IllegalStateException and what caused it on my first post. You can find it
here. Right now, I encountered another one and this time, the servlet caused the exception and not the JSP. Got the solution right
here. First, take a look at my code.
1 2 3 4 5 6 7 8 9 10 | if ( searchesList.size() != 0 && webSearchList.size() != 0 && searchEngineList.size() != 0 ) { request.getRequestDispatcher(FORWARD_VIEW_MONTHLY).forward(request, response); } else { request.getRequestDispatcher(FORWARD_NORECORDS).forward(request, response); } return; |
For some reason, it just throws that IllegalStateException. The main point here through is that the servlet doesn't exit the doPost() or doGet() method right away. The code can be further improved by doing this.
1 2 3 4 5 6 7 8 9 10 | if ( searchesList.size() != 0 && webSearchList.size() != 0 && searchEngineList.size() != 0 ) { request.getRequestDispatcher(FORWARD_VIEW_MONTHLY).forward(request, response); return; } else { request.getRequestDispatcher(FORWARD_NORECORDS).forward(request, response); return; } |
I haven't tested this yet on our development server. But I'm sure that it will work and get rid of that IllegalStateException thing.

UPDATE: 01/23/2007
How silly of me to post this solution without testing it first! It was very stupid of me to say that the return stuff solved the problem. I just wrestled for another whole day searching for the solution because the problem still persisted even after this post. Luckily, I was able to find a solution.
Just replace the lines that use the RequestDispatcher's forward method to include like this
request.getRequestDispatcher(FORWARD_NORECORDS).forward(request, response);
to
request.getRequestDispatcher(FORWARD_NORECORDS).include(request, response);
Whew! Sorted!