5 Replies Latest reply on May 30, 2003 5:33 AM by jonlee

    Browser sends JSP content instead of SVG

    sridharsa

      Hi all,
      I am a newbie to JBoss and JSP. I am trying to display a SVG file which is processed by a JSP (svgDisplay.jsp) and sent back in the response. I am setting the proper content-type (image/svg+xml) which is registered in JBoss also. But when the content comes back, the browser expects me to save the file (as svgDisplay.JSP) instead of displaying the SVG content.

      What could I be doing wrong? One more thing which troubles me is that when I save the content as JSP and open the file, I can see two blank lines at the top of the file. If and only I remove them and change the file extension to SVG, can I see the SVG content on IE. Would the blank lines be the problem somehow?

      Thanks in advance.
      Sridhar.

        • 1. Re: Browser sends JSP content instead of SVG
          sridharsa

          Found out that the page content type which comes back is text/html which prompts me to save the image/svg+xml content. Why is that?

          Also one interesting thing is that, the same setup works (displays the SVG on browser) with Opera but fails with IE6 and NN6.

          Any ideas.
          Sridhar.

          • 2. Re: Browser sends JSP content instead of SVG
            jonlee

            You sure the content-type is the first thing you send on the output stream? I'm a bit vague on this but I think it has to be the first thing on the page before any text output. If it is not, I think it is ignored as the content-type has defaulted because "display" data has already been sent.

            I don't think defining the mime-types in web.xml has any effect on dynamic content, only static-content - associates file postfix with content-type. Dynamic content is governed entirely by the content-type you specify for the stream (where the default is HTML).

            • 3. Re: Browser sends JSP content instead of SVG
              jonlee

              I don't know if this affects you as well but apparently some IE's have problems if the URL doesn't end with .svg. See here:

              http://www.pinkjuice.com/svg/mime.xhtml

              • 4. Re: Browser sends JSP content instead of SVG
                sridharsa

                Okay. Here is what I have found out so far and I am including some gripes and ahh!s.

                Browsers and their quirks
                IE - You need to request the SVG with an .svg or .svgz extension as IE doesn't care about MIME types. Also, we need to embed the SVG (with proper width and height specified) else IE will try to download the file.

                Opera - As far as I can tell, it doesn't work with embedding SVG. It needs to be sent to the browser directly. MIME type necessary and it has to be the first thing sent to the browser. Cannot have any spaces/newlines before the contentType is sent to the browser.

                Netscape - Has version problems so I am going to talk about versions and their quirks below:
                Netscape 6 - Adobe SVG Viewer WILL NOT work with this as apparently some mismatch in implementation (http://support.adobe.com/devsup/devsup.nsf/docs/51392.htm).
                Netscape 7 - Mozilla states that Netscape 7 does not have SVG support "turned on" by default and we need to do some stuff to turn it on. This will not work even if we install Adobe SVG viewer. So, what it does is it recognizes the image/svg+xml MIME type and asks the user whether he wants to open it in Adobe (the associated application for SVG) or Save it to disk. If you choose Adobe, lo! and behold!, it opens in IE as IE is the default browser and Adobe's SVG Viewer is associated with only that. So, even if you send the correct MIME type and without any spaces at the top, it won't work as you expect it to work.

                For all browsers I tested this stuff, I had to remove all spaces, comments etc in my JSP as it introduces spaces above my SVG which craps out promptly at the browser. Grrr!!

                So, all in all, I have spent (read as wasted) 11 hrs on this application just to display a simple SVG file. After all this work, am I still done?!! Noooo!!! I am still stuck. Wanna guess why?!! Because, embedding in IE requires me to specify the dimensions and I have to figure out the dimensions dynamically.

                So, any help in figuring out the dimensions dynamically for a SVG file will be much appreciated.

                Thanks in advance.
                Sridhar.

                • 5. Re: Browser sends JSP content instead of SVG
                  jonlee

                  The only way, and there are plenty of examples through Google, is to have some Javascript in the screen before to detect browser dimensions.