做了个简单的jsp,想要引用fontawesome的图标,下载后,解压并应用,
(1)但是发现无法加载,页面并无foneawesome显示,网上查了下需要在web.xml添加如下:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.woff</url-pattern>
<url-pattern>*.woff2</url-pattern>
</servlet-mapping>
(2)还是没有显示,于是又检查了一遍,把引用代码中的 charset=”utf-8″删除后,有点正常了
<link rel="stylesheet" href="stylesheets/font-awesome.woff" charset="utf-8"/>
修改为:
<link rel="stylesheet" href="font-awesome/fonts/fontawesome-webfont.woff" />
页面显示为一个空框,根据资料,把路径font-awesome/fonts/fontawesome-webfont.woff修改为fonts/fontawesome-webfont.woff;
最终显示正常:
总结解决办法:
(1)确认项目中web.xml添加了woff的servlet-mapping
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.woff</url-pattern>
<url-pattern>*.woff2</url-pattern>
</servlet-mapping>
(2)确认tomcat下web.xml的配置未被注释:
<mime-mapping>
<extension>svg</extension>
<mime-type>image/svg+xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>woff</extension>
<mime-type>application/x-font-woff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>woff2</extension>
<mime-type>application/x-font-woff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ttf</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>otf</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
(3)确认fontwwesome的路径不要过长
(4)在新建jsp会有这么一个标签在顶部:
!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
改为
!DOCTYPE HTML PUBLIC “-//W3C//DTD XTML 4.01 Transitional//EN”
或 <!DOCTYPE HTML> 即可。