最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - .js and .css files are loading as texthtml in my JSP page. - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Jul 14, 2012 at 1:42 SriviSrivi 4173 gold badges7 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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./book/-/page/application.environment.html

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.

发布评论

评论列表(0)

  1. 暂无评论