RE: Sudden IllegalStateException

2004-01-05 Thread Shapira, Yoav

Howdy,
How does a RequestDispatcher forward behave here (as opposed to a
sendRedirect)?  Also, make sure you call encodeRedirectUrl before
redirecting (though this wouldn't cause an IllegalState problem, it's a
good idea).

Yoav Shapira
Millennium ChemInformatics


-Original Message-
From: Merrill Cornish [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 31, 2003 4:54 PM
To: Tomcat Users List
Subject: Sudden IllegalStateException

I have been developing a JSP/servlet application using Tomcat 5.0.16.
Over the past months, I felt that I had learned enough (partially with
the help of this mailing list) about JSP, servlets, and Tomcat that I
could debug most of the obsticales that popped up.  Until this morning.

I  started addnig a new servlet several levels down. Suddenly, I
started getting the following error:

java.lang.IllegalStateException

org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteRes
ponseFacade.java:379)
   Timesheet.LoginServlet.doPost(LoginServlet.java:67)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

When I launch the application, the Tomcat HTML welcome page redirects
via a refresh to my login.jsp page via https.  That login page displays
properly.  When I fill in the login name and password and click on
submit, I immediately get the above exception.  The line number it
references is the following:

  response.sendRedirect(Util.MAIN_MENU_PAGE_URL);

where Util.MAIN_MENU_PAGE_URL is /timesheet/mainMenu.jsp, a valid
page
URL.

This sendRedirect() is the last thing the login servlet does after
validating the login and collecting information about the logged in
user
from the database.  This has all been working for months.

The one time I got an illegal state exception before was when I
accidently did something like session.getAttribute() when the session
was invalid.  However,  the login servlet starts with

HttpSession session = request.getSession(true);

which is the ONLY time it's called with a true argument.  I have also
verified that immediately before the call to sendRedirect(), both the
session and response variables have reasonable values.

Can any one suggest what I may have changed to suddenly get an illegal
state exception?

Merrill Cornish


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Sudden IllegalStateException

2004-01-02 Thread Ben Souther
On Wednesday 31 December 2003 09:00 pm, Merrill Cornish wrote:
 Ben,

 I don't know if it's a good idea or not, but I separate the HTML stuff
 into the JSP pages and use the servlets solely for program logic.
It is a good idea. The MVC pattern is widely accepted as a best practice for 
server side java.  

 Therefore, my servlets never output content..  Instead they merely
 redirect to a JSP page which then contains only enough Java logic to
 collect the data it needs from session attributes.
Are you able to post your servlet/JSP code? If not on the list, you can send 
it to me personally.  I've been working on a fairly large app that uses the 
request dispatcher extensivly without running into this problem.  I'd be 
interested to see what your program is doing.




 Merrill

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Ben Souther
F.W. Davison  Company, Inc.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Sudden IllegalStateException

2004-01-02 Thread Merrill Cornish
Ben,

Yes, I can post the code, but now I'm not sure that will help.

Yesterday I tried my old standby debugging technique of commenting out 
virtually all of the code in the servlet.  It worked.  I then started 
uncommenting portions until it stopped working.  For a while, I thought 
I was winning.  I got it down to where if a call to one subroutine was 
commented out, it worked; but if the subroutine was called, the return 
would fail when it reached the sendRedirect() back in the servlet.  Then 
I noticed that SOMETIMES a call to the subroutine would not fail. [sigh...]

The subroutine in question does database access with no sendRedirect() 
or any other funny business.  Right now, I'm trying to further 
characterize the problem. 

I may still take you up on your offer of help (and thank you, by the 
way), but I need to do some work first.

Thanks,
Merrill
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Sudden IllegalStateException

2004-01-01 Thread Howard Watson
Hello Merrill

If you're still working on this tomorrow and you want to share your code I'd be 
willing to walk it through.

Howard Watson
Database Administrator
Easter Seals-Goodwill Northern Rocky Mountain
4400 Central Avenue
Great Falls, Montana  59405
(406) 771-3759
[EMAIL PROTECTED]
 [EMAIL PROTECTED] 12/31/03 14:59 PM 
I have been developing a JSP/servlet application using Tomcat 5.0.16.  
Over the past months, I felt that I had learned enough (partially with 
the help of this mailing list) about JSP, servlets, and Tomcat that I 
could debug most of the obsticales that popped up.  Until this morning. 

I  started addnig a new servlet several levels down. Suddenly, I 
started getting the following error:

java.lang.IllegalStateException

org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteResponseFacade.java:379)
Timesheet.LoginServlet.doPost(LoginServlet.java:67)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

When I launch the application, the Tomcat HTML welcome page redirects 
via a refresh to my login.jsp page via https.  That login page displays 
properly.  When I fill in the login name and password and click on 
submit, I immediately get the above exception.  The line number it 
references is the following:

  response.sendRedirect(Util.MAIN_MENU_PAGE_URL);

where Util.MAIN_MENU_PAGE_URL is /timesheet/mainMenu.jsp, a valid page 
URL.

This sendRedirect() is the last thing the login servlet does after 
validating the login and collecting information about the logged in user 
from the database.  This has all been working for months.

The one time I got an illegal state exception before was when I 
accidently did something like session.getAttribute() when the session 
was invalid.  However,  the login servlet starts with

HttpSession session = request.getSession(true);

which is the ONLY time it's called with a true argument.  I have also 
verified that immediately before the call to sendRedirect(), both the 
session and response variables have reasonable values.

Can any one suggest what I may have changed to suddenly get an illegal 
state exception?

Merrill Cornish


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Sudden IllegalStateException

2003-12-31 Thread Howard Watson
From here: http://jakarta.apache.org/tomcat/faq/misc.html#illegalstate

Why do I get java.lang.IllegalStateException? 
These are the most common reasons how you can get an java.lang.IllegalStateException: 
Calling setBufferSize and content has been written. 
The response has been committed and you do any of the following: 
Calling ServletResponse.reset() or ServletResponse.resetBuffer() 
Calling either HttpServletResponse.sendError() or HttpServletResponse.sendRedirect(). 
Calling RequestDispatcher.forward() which includes performing a jsp:forward 
Calling RequestDispatcher.forward() which includes performing a jsp:forward

I did it the other day like this:

added this line to an existing page - not thinking forced the session to null for 
testing
if (session null) {send.redirect sessionTimeoutPage}

this code already existed
some more code

sendRedirect to next valid page

added in else and fixed it

 [EMAIL PROTECTED] 12/31/03 02:54PM 
I have been developing a JSP/servlet application using Tomcat 5.0.16.  
Over the past months, I felt that I had learned enough (partially with 
the help of this mailing list) about JSP, servlets, and Tomcat that I 
could debug most of the obsticales that popped up.  Until this morning. 

I  started addnig a new servlet several levels down. Suddenly, I 
started getting the following error:

java.lang.IllegalStateException

org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteResponseFacade.java:379)
Timesheet.LoginServlet.doPost(LoginServlet.java:67)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

When I launch the application, the Tomcat HTML welcome page redirects 
via a refresh to my login.jsp page via https.  That login page displays 
properly.  When I fill in the login name and password and click on 
submit, I immediately get the above exception.  The line number it 
references is the following:

  response.sendRedirect(Util.MAIN_MENU_PAGE_URL);

where Util.MAIN_MENU_PAGE_URL is /timesheet/mainMenu.jsp, a valid page 
URL.

This sendRedirect() is the last thing the login servlet does after 
validating the login and collecting information about the logged in user 
from the database.  This has all been working for months.

The one time I got an illegal state exception before was when I 
accidently did something like session.getAttribute() when the session 
was invalid.  However,  the login servlet starts with

HttpSession session = request.getSession(true);

which is the ONLY time it's called with a true argument.  I have also 
verified that immediately before the call to sendRedirect(), both the 
session and response variables have reasonable values.

Can any one suggest what I may have changed to suddenly get an illegal 
state exception?

Merrill Cornish


-
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Sudden IllegalStateException

2003-12-31 Thread Merrill Cornish
Howard,

I had already read the misc.html#illegalstate.  In my case, I KNOW the 
illegal state was triggered by sendRedirect() since that's what's in the 
trace back.  Also, I've already verified that immediately before the 
call to sendRedirect(), both session and response are OK.

I forgot to mention in the first post that I've already tried stopping 
and starting Tomcat, stopping and relaunching the browser, and 
recompiling all servlets.  My question is WHY is sendRedirect() causing 
the problem.

Merrill

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Sudden IllegalStateException

2003-12-31 Thread Howard Watson
Are you real sure that you do not have more than one sendRedirect in your code that 
can be processed sequentially? The first one will set a header and the second will 
throw an error. 

Have a Happy New Year!

 [EMAIL PROTECTED] 12/31/03 03:43PM 
Howard,

I had already read the misc.html#illegalstate.  In my case, I KNOW the 
illegal state was triggered by sendRedirect() since that's what's in the 
trace back.  Also, I've already verified that immediately before the 
call to sendRedirect(), both session and response are OK.

I forgot to mention in the first post that I've already tried stopping 
and starting Tomcat, stopping and relaunching the browser, and 
recompiling all servlets.  My question is WHY is sendRedirect() causing 
the problem.

Merrill


-
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Sudden IllegalStateException

2003-12-31 Thread Merrill Cornish
Howard,

There are three sendRedirect() calls in the servlet.  The first two 
redirect back to the login page if with the login user id is not found 
or  the login password doesn't match.  In both cases, the sendRedirect() 
is immediately followed by a return.  (I learned to use explicit returns 
after sendRedirect() some time ago.)

The sendRedirect() that is throwing the error is the last statement in 
the overall try{} block.  There is a catch for SQLException which calls 
a function that would call sendRedirect() to get to the error page, but 
if we've gotten to the last statement in the try{} block, there was no 
SQLException. The only thing after the try{}/catch{} is again a return.

Merrill

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Sudden IllegalStateException

2003-12-31 Thread Ben Souther
I'd be more concerned with what is before it. 
If anything writes to either the page or the headers before a redirect, it 
will throw an IllegalStateException.

Did you set a content type?


On Wednesday 31 December 2003 06:34 pm, you wrote:
 Howard,

 There are three sendRedirect() calls in the servlet.  The first two
 redirect back to the login page if with the login user id is not found
 or  the login password doesn't match.  In both cases, the sendRedirect()
 is immediately followed by a return.  (I learned to use explicit returns
 after sendRedirect() some time ago.)

 The sendRedirect() that is throwing the error is the last statement in
 the overall try{} block.  There is a catch for SQLException which calls
 a function that would call sendRedirect() to get to the error page, but
 if we've gotten to the last statement in the try{} block, there was no
 SQLException. The only thing after the try{}/catch{} is again a return.

 Merrill

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Sudden IllegalStateException

2003-12-31 Thread Howard Watson
May be I'm trying to help with something over my head. When I had this error I read 
about using Return and could not visualize where from a servlet I would return to in a 
JSP., so I know I need to research this.

However, the point is from the faq link I gave you:
 These are the most common reasons how you can get an java.lang.IllegalStateException:
 The response has been committed and you do any of the following

which I believe is same thing bpsouther is saying.

If for instance you execute sendRedirect and a doPost begins to execute (this was my 
case) and encounters another sendRedirect you will get an error because the previous 
sendRedirect has already set the header.

The key thing is that somewhere in your nested code a response has begun before the 
sendRedirect that is throwing an error.

Since at this point I can't visualize a single Return I probably can't help you with a 
nested Return.


 [EMAIL PROTECTED] 12/31/03 16:40 PM 
Howard,

There are three sendRedirect() calls in the servlet.  The first two 
redirect back to the login page if with the login user id is not found 
or  the login password doesn't match.  In both cases, the sendRedirect() 
is immediately followed by a return.  (I learned to use explicit returns 
after sendRedirect() some time ago.)

The sendRedirect() that is throwing the error is the last statement in 
the overall try{} block.  There is a catch for SQLException which calls 
a function that would call sendRedirect() to get to the error page, but 
if we've gotten to the last statement in the try{} block, there was no 
SQLException. The only thing after the try{}/catch{} is again a return.

Merrill

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Sudden IllegalStateException

2003-12-31 Thread Merrill Cornish
Ben,

I don't know if it's a good idea or not, but I separate the HTML stuff 
into the JSP pages and use the servlets solely for program logic.  
Therefore, my servlets never output content..  Instead they merely 
redirect to a JSP page which then contains only enough Java logic to 
collect the data it needs from session attributes.

Merrill

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]