glyphicons-halflings-regular.ttf 404

时间:2023-03-09 19:22:06
glyphicons-halflings-regular.ttf 404

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

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

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

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

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

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

     <servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.ttf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.woff</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.woff2</url-pattern>
</servlet-mapping>

⑥ OK,测试通过。

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

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

 @font-face {
font-family: 'Glyphicons Halflings'; src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'),
url('../fonts/glyphicons-halflings-regular.woff') format('woff'),
url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'),
url('../fonts/glyphicons-halflings regular.svg#glyphicons_halflingsregular') format('svg');
}

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

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