aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question about redirecting. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Question about redirecting." Watch "Question about redirecting." New topic
Author

Question about redirecting.

Otto Teixeira
Greenhorn

Joined: Aug 10, 2005
Posts: 12
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

Joined: Dec 04, 2004
Posts: 950
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


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Otto Teixeira
Greenhorn

Joined: Aug 10, 2005
Posts: 12
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
 
subject: Question about redirecting.