0

Learning JSP and have an issue with the css/js content not loading. I have a jsp page, where I have bootstrap css and js referenced using standard html link and script tags:

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

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 file="/bootstrap/css/bootstrap.css"%>

The jsp has the following @page and meta tags:

<%@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:

<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; using Tomcat 7, and eclipse and this is in a maven project.

Justin
  • 4,461
  • 22
  • 87
  • 152

2 Answers2

0

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. Everything else in the package updates fine (as far as I can tell), except for the 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). 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.

Weird.

Justin
  • 4,461
  • 22
  • 87
  • 152
-1

Removing this line in jsp resolved the error for us. We were facing the issue when using Tomcat 8.5.59