4

When I load my jsp page, the attached css and js files are rendered as text/html format. I noticed it from chrome browser where I could see this error message

"Resource interpreted as Script but transferred with MIME type text/html"

I have specified the mime type in web.xml as follows,

    <mime-mapping>    
        <extension>js</extension>        
        <mime-type>application/javascript</mime-type>        
    </mime-mapping>

    <mime-mapping>    
        <extension>css</extension>        
        <mime-type>text/css</mime-type>        
    </mime-mapping>
    <mime-mapping>    
        <extension>jpg</extension>        
        <mime-type>image/jpeg</mime-type>        
    </mime-mapping>

The server where I am running my application is Apache Tomcat 7. I created this JSP file inside the Vaadin Project.

My questions are, Should I need to change the Mime type somewhere else in Tomcat configuration ? is there any limitation to include the CSS and JS files in a JSP page?
or Is it because of Vaadin framework?

I am just a beginner trying to learn JSP and vaadin framework.

2 Answers 2

4

I finally found the reason for this issue. I just fixed web.xml by changing the default url mapping

eg. from the default value as below

<servlet-mapping>
    <servlet-name>My Application</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

to

<servlet-mapping>
    <servlet-name>My Application</servlet-name>
    <url-pattern>/home/*</url-pattern>
</servlet-mapping>

After changing this I still got an error which I fixed by adding

<servlet-mapping>
<servlet-name>My Application</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>

which is covered in the Book of Vaadin, section 4.8 https://vaadin.com/book/-/page/application.environment.html

0
0

In my case, I have a filter in my web.xml that filters everything. (It redirects to a certain page based on the IP address.)

<filter-mapping>
    <filter-name>RedirectFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

With this filter mapping, all requests (including images, stylesheets, scripts, etc.) go through the filter. You can fix it by either removing the filter-mapping from your web.xml or checking the logic in the filter-class to allow or ignore the resources.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.