![](/img/trans.png)
[英]JSP pages not loading on loaclhost while working with Tomcat7 on Eclipse IDE
[英]JSP Tomcat7 static css and js files not loading
正在学习 JSP 并遇到 css/js 内容未加载的问题。 我有一个 jsp 页面,在那里我使用标准的 html 链接和脚本标签引用了 bootstrap 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">
我尝试使用谷歌搜索并找到 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 项目中。
对我来说,解决方案很奇怪。 自从我在 eclipse/maven 中构建项目以来,对 web.xml 文件的更改并未反映在 tomcat webapp 应用程序目录中的 web.xml 中。 包中的其他所有内容都更新得很好(据我所知),除了 web.xml?
所以我在 eclipse 中的 target >> project-SNAPSHOT >> WEB-INF >> web.xml (应该是派生的)中找到了 web.xml 文件。 在那里强制更改并且它起作用了,更改被拾取并且我的原始问题消失了。
我猜我无意中破坏了某种类型的依赖链接或以某种方式沿途的某些东西,但是一旦我重新添加了 servlet、映射等,一切正常。
奇怪的。
在 jsp 中删除这一行为我们解决了错误。 我们在使用 Tomcat 8.5.59 时遇到了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.