Detecting ie6 in jsps (jstl) to change png to gif

Tuesday, June 10th, 2008

I’m just learning how to integrate css into jsps, but I’m lucky enough to have people around to help me out! As a designer, I want to make sure browsers degrade as gracefully as possible, and so I asked Dan, one of our developers, how you would replace png images for map markers into gifs for ie 6. Usually I would just declare this in the css, but here we were appending a number at the end of each image and then appending the .png. Looking online didn’t uncover any “beautiful” solutions (as Dan would say).

Luckily we were already detecting our header values (apparently it’s implicit in all jsps), so it was a matter of asking the program to detect the browser (User-Agent):

<c:set var=”userAgent” value=”${header['User-Agent']} />

And that’s it! I needed to call in the variable for other things, and it was just necessary to use this:
${isIE6orBelow ? ‘gif’:'png’}



One comment

  1. Charlie says:

    Thanks for this code fragment. It saved me time. However it can’t be cut and paste due to non-ascii ” and ‘ marks used. Also it is missing he closing ” mark on the value=” ” parts.

Leave a Reply

(will not be published)