简体   繁体   English

JSP Tomcat7 静态 css 和 js 文件未加载

[英]JSP Tomcat7 static css and js files not loading

Learning JSP and have an issue with the css/js content not loading.正在学习 JSP 并遇到 css/js 内容未加载的问题。 I have a jsp page, where I have bootstrap css and js referenced using standard html link and script tags:我有一个 jsp 页面,在那里我使用标准的 html 链接和脚本标签引用了 bootstrap css 和 js:

 <link rel="stylesheet" type="text/css" link="/bootstrap/css/bootstrap.css" />

and

<script src="/WebIntro/bootstrap/js/bootstrap.js"></script>

neither of them work and Chrome is giving me the following on the console:它们都不起作用,Chrome 在控制台上给了我以下信息:

Resource interpreted as Stylesheet but transferred with MIME type text/plain:

If I use an include directive, it works for the css but pulls all the content into the file:如果我使用 include 指令,它适用于 css 但将所有内容拉入文件:

<%@include file="/bootstrap/css/bootstrap.css"%>

The jsp has the following @page and meta tags: jsp 具有以下 @page 和 meta 标签:

<%@page contentType="text/html" %>

and

<meta http-equiv = "Content-Language" content = "en"/>
<meta http-equiv = "Content-Type" content="text/html; charset=utf-8">

I tried googling and found the mime-mapping element for the web.xml but the following seems to have no affect:我尝试使用谷歌搜索并找到 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>

If there is some standard Tomcat config that needs to happen I am unaware as I am new to Tomcat;如果有一些标准的 Tomcat 配置需要发生,我不知道,因为我是 Tomcat 的新手; using Tomcat 7, and eclipse and this is in a maven project.使用 Tomcat 7 和 eclipse,这是在一个 Maven 项目中。

The solution for me was very strange.对我来说,解决方案很奇怪。 The changes to the web.xml file that was present since I built the project in eclipse/maven, weren't reflected in the web.xml within tomcat webapp application directories.自从我在 eclipse/maven 中构建项目以来,对 web.xml 文件的更改并未反映在 tomcat webapp 应用程序目录中的 web.xml 中。 Everything else in the package updates fine (as far as I can tell), except for the web.xml?包中的其他所有内容都更新得很好(据我所知),除了 web.xml?

So I found the web.xml file within eclipse inside target >> project-SNAPSHOT >> WEB-INF >> web.xml (which is supposed to be derived).所以我在 eclipse 中的 target >> project-SNAPSHOT >> WEB-INF >> web.xml (应该是派生的)中找到了 web.xml 文件。 Forced changes there and it worked, changes were picked up and my original issue gone.在那里强制更改并且它起作用了,更改被拾取并且我的原始问题消失了。

I am guessing I had inadvertently broken some type of dependency link or something along the way somehow, but once I added the servlet, mappings, etc back in, everything worked fine.我猜我无意中破坏了某种类型的依赖链接或以某种方式沿途的某些东西,但是一旦我重新添加了 servlet、映射等,一切正常。

Weird.奇怪的。

Removing this line in jsp resolved the error for us.在 jsp 中删除这一行为我们解决了错误。 We were facing the issue when using Tomcat 8.5.59我们在使用 Tomcat 8.5.59 时遇到了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM