Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

AJAX Exception handling

Thread view: 
bearsfoot@gmail.com - 13 Feb 2007 12:24 GMT
Hi,

I hope this is the correct group.

How should a HttpServlet include custom errors in in AJAX response.

I need to be able to control some client side behaviour based on the
error returned.

I have tried using cuctom status codes in the
HttpServletResponse.setStatus() and sendError() methods but I always
receieve a Status 500 such as in response below.
If an exception is thrown by the servlet a Status 500 is also
returned.

Thanks in advance.

===========================================
responseText = Error 500: null ErrorMessage
           Error 500: Server caught unhandled exception from servlet
[testServlet]: ERROR: Cannot set header.               Response
already committed.
responseXML.xml =
status = 500
statusText = Internal Server Error
Silvio Bierman - 13 Feb 2007 16:35 GMT
> Hi,
>
[quoted text clipped - 21 lines]
> status = 500
> statusText = Internal Server Error

At the time the exception occurs you have already written to the response.
Therefore, a response header can not be written.

The simplest but not neccesarily most efficient way to handle this is
generate the response to a seperate buffer
(StringWriter/ByteArrayOutputStream will do) and write that out at once if
no errrors occur or just set the error status if one does occur.

Regards,

Silvio Bierman


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.