簡體   English   中英

JBoss上的Javascript源文件具有錯誤的content-type / mime類型?

[英]Javascript source files on JBoss have the wrong content-type/mime type?

我正在編寫一個JSP應用程序,並將其部署到JBoss 5.0。 當我嘗試檢索CSS或Javascript文件時,JBoss返回的文件的Content-type錯誤,因此Firefox拒絕執行其中提供的代碼。 這是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">

   <display-name>TestServlet</display-name>

   <servlet>
      <servlet-name>TestServlet</servlet-name>
      <servlet-class>org.example.TestServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
      <servlet-name>TestServlet</servlet-name>
      <url-pattern>/engine/*</url-pattern>
   </servlet-mapping>

   <welcome-file-list>
      <welcome-file>
         /login.jsp
      </welcome-file>
   </welcome-file-list>
   <jsp-config>
      <jsp-property-group>
         <display-name>TestServlet</display-name>
         <url-pattern>/*</url-pattern>
         <el-ignored>false</el-ignored>
         <scripting-invalid>false</scripting-invalid>
         <is-xml>false</is-xml>
         <trim-directive-whitespaces>true</trim-directive-whitespaces>
      </jsp-property-group>
   </jsp-config>

   <mime-mapping>
      <extension>css</extension>
      <mime-type>text/css</mime-type>
   </mime-mapping>
   <mime-mapping>
      <extension>js</extension>
      <mime-type>text/javascript</mime-type>
   </mime-mapping>
</web-app>

使用lynx測試文件下載,我得到以下信息:

主機> lynx http:// devbox:8080 / TestServlet / js / main.js -head -dump

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
Set-Cookie: JSESSIONID=EA6FFF63B00F0B8C0C44F7A79BD368CF; Path=/jclaim
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 1778
Date: Sun, 24 May 2009 17:53:31 GMT
Connection: close

我通過更改以下內容找到了答案:

  <jsp-property-group>
     <display-name>TestServlet</display-name>
     <url-pattern>/*</url-pattern>

改為:

  <jsp-property-group>
     <display-name>TestServlet</display-name>
     <url-pattern>*.jsp</url-pattern>

作為JSP的初學者,我不確定我從哪個教程中學到了前面的示例,但是並沒有帶來很多挫敗感。

lynx命令現在導致:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
Accept-Ranges: bytes
ETag: W/"11038-1243181792000"
Last-Modified: Sun, 24 May 2009 16:16:32 GMT
Content-Type: text/javascript
Content-Length: 11038
Date: Sun, 24 May 2009 17:57:07 GMT
Connection: close

這也適用於CSS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM