glyphicons-halflings-regular.ttf 404

这个是用bootstrap框架时我遇到的问题,个人解决过程如下:

① 这个资源不是我手动引用的,是bootstrap.min.css文件间接调用的。

② 默认的路径是css文件路径是project/css,引用的路径是project/fonts/*.ttf。

③ 添加fonts文件夹和文件,依然提示该错误,但是直接访问*.css文件就没问题。

④ 想起静态资源的调用是通过tomcat手动配置的。

⑤ 增加这些文件的匹配规则,在web.xml中增加如下配置:

 1     <servlet-mapping>
 2         <servlet-name>default</servlet-name>
 3         <url-pattern>*.ttf</url-pattern>
 4     </servlet-mapping>
 5     <servlet-mapping>
 6         <servlet-name>default</servlet-name>
 7         <url-pattern>*.woff</url-pattern>
 8     </servlet-mapping>
 9     <servlet-mapping>
10         <servlet-name>default</servlet-name>
11         <url-pattern>*.woff2</url-pattern>
12     </servlet-mapping>

⑥ OK,测试通过。

不想使用默认的文件路径怎么办?

⑦ 修改bootstrap.css关于ttf等资源调用的路径信息:

 1 @font-face {
 2   font-family: 'Glyphicons Halflings';
 3 
 4   src: url('../fonts/glyphicons-halflings-regular.eot');
 5   src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), 
 6   url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'),
 7   url('../fonts/glyphicons-halflings-regular.woff') format('woff'),
 8   url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'),
 9   url('../fonts/glyphicons-halflings       regular.svg#glyphicons_halflingsregular') format('svg');
10 }

将fonts文件夹改成你实际的资源路径,然后引用bootstrap.css。

⑧ 这时发现bootstrap.css需要用到bootstrap.css.map文件。具体关系和原理尚需继续学习。

原文地址:https://www.cnblogs.com/yoyotl/p/5105683.html