学习JSP并遇到css / js内容无法加载的问题。我有一个jsp页面,我使用标准的html链接和脚本标签引用了引导程序css和js:
<link rel="stylesheet" type="text/css" link="/bootstrap/css/bootstrap.css" />
和
<script src="/WebIntro/bootstrap/js/bootstrap.js"></script>
它们都不起作用,Chrome在控制台上给我以下内容:
Resource interpreted as Stylesheet but transferred with MIME type text/plain:
如果我使用include指令,它适用于css,但会将所有内容提取到文件中:
<%@include file="/bootstrap/css/bootstrap.css"%>
jsp具有以下@page和meta标记:
<%@page contentType="text/html" %>
和
<meta http-equiv = "Content-Language" content = "en"/>
<meta http-equiv = "Content-Type" content="text/html; charset=utf-8">
我尝试使用Google搜索并找到了web.xml的mime-mapping元素,但以下似乎没有任何影响:
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>application/javascript</mime-type>
</mime-mapping>
如果有一些标准的Tomcat配置需要发生,我不知道因为我是Tomcat的新手;使用Tomcat 7和eclipse,这是一个maven项目。
答案 0 :(得分:0)
对我来说解决方案很奇怪。自从我在eclipse / maven中构建项目以来,对web.xml文件所做的更改未反映在tomcat webapp应用程序目录中的web.xml中。除了web.xml之外,包中的其他所有内容都更新(据我所知)?
所以我在目标&gt;&gt;内的eclipse中找到了web.xml文件project-SNAPSHOT&gt;&gt; WEB-INF&gt;&gt; web.xml(应该是派生的)。那里强制改变并且有效,改变被拾起并且我的原始问题消失了。
我猜我在某种程度上无意中破坏了某种类型的依赖链接或某种东西,但是一旦我添加了servlet,映射等,一切都运行正常。
怪异。
答案 1 :(得分:-1)
在jsp中删除此行为我们解决了该错误。 我们在使用Tomcat 8.5.59时遇到了问题