File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about redirecting.

 
Otto Teixeira
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

According to HFSJ, I should get an IllegalStateException if I try to redirect or dispatch the request AFTER writing to the response. The problem is that isn't happening. Why not?

In any servlet's doPost():


The sendRedirect() is simply ignored. If I comment the flush() line, it gets redirected, but still without the exception.

Thank you.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The sendRedirect() is simply ignored. If I comment the flush() line, it gets redirected, but still without the exception.


After the flush(), the server surly throw the exception, bu as the response is commited it will not display in your browser. Check your server log. It should printed there.

Without flush, though you are writing to the response writer, the response is not commited ( as thers is some buffering for the writer), the serdRedirect will work without any exception.

Thanks
 
Otto Teixeira
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right.

SEVERE: Servlet.service() for servlet Testando threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed


I was thinking about something like that... the exception being "hidden" by the container.

Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic