SVG Display exception

Source: Internet
Author: User
Tags response code

Today in the deployment process, found in the formal environment above SVG can not display normally, excited mood immediately was poured a basin of cold water, before the development of the time is under Tomcat, show everything is normal, it is the environment for Websphere,svg will not show out.
First guess the resource is not found, through the browser access to find the response code 302, indicating that the resource is actually looking for, since the resources exist, the same browser, only the environment, the cause of this phenomenon should be on the server, by observing the developer Tools console, suddenly found that SVG files are clipped, But the mine type of the response is text, which is obviously incorrect, guessing that this is why the browser is not able to recognize the SVG file properly, so it did a bit of testing.

First write an SVG file: circle.svg

<?xml version= "1.0" standalone= "no"?><! DOCTYPE svg public "-//W3C//DTD svg 1.1//en" "Http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" ><svg width="100%" height="100%" version="1.1"  xmlns="Http://www.w3.org/2000/svg"><circle cx=" +" cy= " r" ="40"  Stroke="Black"stroke-width="2" fill="Red" /></svg>

Then write a JSP that displays SVG via an IMG tag.

<%@ page language="java" contenttype="text/html; Charset=utf-8 "pageencoding="utf-8"%><! DOCTYPE html><html><head><meta charset="Utf-8"><title>Test</title></head><body><img alt="svg" src="Circle.svg"/></body></html>

Start server, browser Access JSP page, display normal

Change the Web. XML, add the mine type of SVG in it, modify it to Text/plain, revisit it, and see the results.

<mime-mapping>    <extension>svg</extension>    <mime-type>text/plain</mime-type></mime-mapping>

The SVG image has been found to be unable to display properly.

Https://www.w3.org/services/svg-server/also has a description about the mine type of SVG file, The final solution is to add the SVG mine type configuration to the Web. xml file to ensure that the server responds correctly and the browser loads properly.

<mime-mapping>   <extension>Svg</extension>   <mime-type>Image/svg+xml</mime-type></mime-mapping><mime-mapping>   <extension>Svgz</extension>   <mime-type>Image/svg+xml</mime-type></mime-mapping>

SVG Display exception

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.