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