views:

62

answers:

1

I have the following image tag in a JSP:

<img id="validationGraph" src="/myapp/MyServlet?mode=myMode" 
 usemap="#validationMap" border="0" onLoad="getImageMap()" />

A Java servlet uses JFreeChart to generate a png image and write it to the output stream. This works fine in Firefox and Chrome, but I am getting an intermittent error in IE. In all 3 browsers, the image does actually load every time. But most of the time in IE, I get an "Object expected" error on the img tag line and the getImageMap() function fails to fire. Sometimes the page loads fine in IE with no error message and with the getImageMap function firing.

I thought perhaps an Ajax call in getImageMap() was causing the intermittent problem, so I put some alerts in that function. One of the alerts is the very first line of the function. When IE works correctly, the various alerts pop up as expected. When IE reports that error message, NONE of the alerts popup. So it looks like IE isn't even entering the getImageMap() function when this particular error occurs.

I have tried various troubleshooting/debugging, and I can't find the root cause of this problem. Any suggestions?

A: 

The Object Expected error is usually displayed when you try to call a method or access a property on an object and that object is null.

You have an error in your JavaScript that happens once in a while. I suspect that it is code that depends on the getImageMap function to run. If I remember correctly, the onLoad event on images is tricky on IE because it only fires if the images is loaded from the server.

It might be possible that once in a while IE takes the image from its cache instead of going to the server (and no longer fires the event)? Add a timestamp to each servlet call and see if it removes the problem:

src="/myapp/MyServlet?mode=myMode&tstmp=unique_value_for_each_call_to_invalidate_browser_cache" 
dpb