.js和.css文件以text/html格式加载到我的JSP页面中. [英] .js and .css files are loading as text/html in my JSP page.

查看:200
本文介绍了.js和.css文件以text/html格式加载到我的JSP页面中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我加载我的jsp页面时,附加的CSS和js文件呈现为text/html格式. 我从chrome浏览器中注意到了它,在那里我可以看到此错误消息

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

将资源解释为脚本,但使用MIME类型text/html进行传输"

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

我已经在web.xml中指定了mime类型,如下所示,

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>

运行我的应用程序的服务器是Apache Tomcat7.我在Vaadin项目中创建了这个JSP文件.

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

我的问题是, 我需要在Tomcat配置中的其他位置更改Mime类型吗? 在JSP页面中包括CSS和JS文件是否有任何限制?
还是因为Vaadin框架?

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?

我只是一个初学者,尝试学习JSP和vaadin框架.

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

推荐答案

我终于找到了此问题的原因.我只是通过更改默认的URL映射来修复了web.xml

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>

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

在《瓦丹经》第4.8节中有介绍 https://vaadin.com/book/-/page/application.environment.html

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

这篇关于.js和.css文件以text/html格式加载到我的JSP页面中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆