【问题标题】:JSP Tomcat7 static css and js files not loadingJSP Tomcat7静态css和js文件未加载
【发布时间】:2017-05-07 19:10:38
【问题描述】:

学习 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:

如果我使用包含指令,它适用于 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 项目。

【问题讨论】:

标签: java html css jsp tomcat


【解决方案1】:

对我来说解决方案很奇怪。自从我在 eclipse/maven 中构建项目以来,对 web.xml 文件的更改并未反映在 tomcat webapp 应用程序目录中的 web.xml 中。包中的其他所有内容都可以正常更新(据我所知),除了 web.xml?

所以我在 eclipse 内的 target >> project-SNAPSHOT >> WEB-INF >> web.xml 中找到了 web.xml 文件(应该是派生的)。在那里强制更改并且它起作用了,更改被拾取并且我原来的问题消失了。

我猜我无意中破坏了某种类型的依赖链接或某种方式,但是一旦我添加了 servlet、映射等,一切正常。

很奇怪。

【讨论】:

    【解决方案2】:

    在 jsp 中删除这一行为我们解决了错误。 我们在使用 Tomcat 8.5.59 时遇到了这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 2020-08-31
      • 2017-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多